question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

languageFileRegex is not compatible with all BCP 47 language tags

See original GitHub issue

Hello! Recently we have added a few custom languages to our project, and to stay consistent, we assigned them to well-formed but invalid language tags (to avoid any collisions) — e.g. en-LOLCAT (this is also non-canoncial apparently, lolcat should be lowercase, but oh well). We have found that browsers do not have any troubles with such codes, falling back to en (which is expected, LOLCAT is a subset of English). However, we have found that svelte-intl-precompile has a pretty weak regular expression to detect which file is compatible for compilation, which prevents us from compiling and shipping our custom languages.

The regular expression in question is:

https://github.com/cibernox/svelte-intl-precompile/blob/1e4a3831912abdc8be0d6ddaeeba5d3305f659ec/sveltekit-plugin.js#L26

Not only does this affect our silly custom languages, this also affects many actual languages and subsets of languages defined in CLDR. You can see this on Regex101.

I have not yet looked into how this regular expression is used, but since Node.js has already enabled compilation with full ICU, wouldn’t it make sense to use actual APIs like Intl.NumberFormat.supportedLocalesOf over regular expressions that can be flawed in one of way or another? Just iterate over files, check if they have compatible extensions and that Intl API considers code valid. This would probably work in our case, and in many other cases…

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
cibernoxcommented, Jun 5, 2022

Cool, I’ll give it a go tonight

1reaction
cibernoxcommented, Jun 6, 2022

I published in 0.11.0-beta.2 in case that’s more convenient.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is html a language tag? · Issue #1 · sebinsua/ietf-language-tag ...
No, html is not a language tag, algorithm needs to be looked at. ... languageFileRegex is not compatible with all BCP 47 language...
Read more >
Language tags in HTML and XML - W3C
Language tag syntax is defined by the IETF 's BCP 47. BCP stands for 'Best Current Practice', and is a persistent name for...
Read more >
JavaScript: Language Tags (BCP 47) - TechOnTheNet
Language Tag Language Region ar‑SA Arabic Saudi Arabia bn‑BD Bangla Bangladesh bn‑IN Bangla India
Read more >
IETF language tag - Wikipedia
An IETF BCP 47 language tag is a standardized code or tag that is used to identify human languages in the Internet. The...
Read more >
bcp-47-match - npm
Match BCP 47 language tags with language ranges per RFC 4647. Latest version: 2.0.3, last published: a month ago. Start using bcp-47-match ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found