languageFileRegex is not compatible with all BCP 47 language tags
See original GitHub issueHello! 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:
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:
- Created a year ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Cool, I’ll give it a go tonight
I published in 0.11.0-beta.2 in case that’s more convenient.