Fallback language not found if $locale is not listed in dictionary
See original GitHub issueDescribe the bug I have a website that can handle hundreds of languages decided by their authors. some support pages are maintained by us and by a small supported amount of languages.
Currently the page locale is selected based on whatever the user currently is having or the author has selected for that content, this is likely to be not covered by the dictionaries.
For instance, we support en-GB
language and also this one is the fallback language if the user has selected one without dictionary.
But when the user selects en-AU
. Then i18n fails and none is loaded.
Is all languages to be expected to be part of dictionaries?
In the console log I get the following message as example (and many more with the same):
[svelte-i18n] The message "page.help.title" was not found in "en", "en-AU", "en", "en-GB".
but the dictionary works and the language is loaded:
{
"en-GB": {
"page": {
"help": {
"title": "Need some help?",
...
},
...
}
},
"zh-CN": {...},
... // IMPORTANT: en-AU is NOT a dictionary supported and is not in this list
}
As soon as i switch the language by clicking on en-GB
all works again, and also if the language is covered by the dictionaries (ex: zh-CN
) even if some translations for that language are missing.
Does all the languages has to be included as dictionaries? The fallback method should always work I believe
How do I load dictionaries:
register('en-GB', () => import('..../en-GB.json'));
register('zh-CN', () => import('..../zh-CN.json'));
... // IMPORTANT: en-AU is NOT a dictionary supported and is not registered here
init({
fallbackLocale: 'en-GB',
initialLocale: 'en-GB',
});
How locale is set by user actions:
$: if ($lang !== undefined) { // Lang is reactive and selected by the options of the page, NOT the locales available
const l = $lang;
setLang(l); // some local cookies for usage to handle reload
const parsedLang = isChineseSpecific(l) ? 'zh-CN' : l; // Chinese fix to force simplified instead of traditional chinese
if ($locale !== parsedLang) {
$locale = parsedLang; // if users is on `en-AU`, support pages should use still the fallback `en-GB`, but it fails.
}
}
Logs
main.js:1147 [svelte-i18n] The message "page.help.title" was not found in "en", "en-AU", "en", "en-GB".
main.js:1147 [svelte-i18n] The message "page.help.subtitle" was not found in "en", "en-AU", "en", "en-GB".
main.js:1147 [svelte-i18n] The message "page.help.text" was not found in "en", "en-AU", "en", "en-GB".
Stacktrace for the first line
main.js:1147 [svelte-i18n] The message "page.help.title" was not found in "en", "en-AU", "en", "en-GB".
[svelte-i18n] The message “page.help.title” was not found in “en”, “en-AU”, “en”, “en-GB”. console.<computed> @ main.js:1147 B @ main.js:10229 instance @ help.js:116 init @ main.js:910 Help @ help.js:150 create_default_slot @ main.js:2380 create_slot @ main.js:110 create_fragment @ main.js:1180 init @ main.js:925 Noop @ main.js:1247 create_each_block$1 @ main.js:2478 update_keyed_each @ main.js:731 update @ main.js:2175 update @ main.js:2591 update @ main.js:420 flush @ main.js:388 Promise.then (async) schedule_update @ main.js:363 make_dirty @ main.js:880 (anonymous) @ main.js:916 onComponentLoaded @ main.js:2682 Promise.then (async) setComponent @ main.js:2702 $$self.$$.update @ main.js:2797 update @ main.js:416 flush @ main.js:388 Promise.then (async) schedule_update @ main.js:363 make_dirty @ main.js:880 (anonymous) @ main.js:916 callback @ main.js:3126 updatePage @ main.js:2897 async function (async) updatePage @ main.js:2894 updatePage @ main.js:3124 goto @ main.js:1931 onTutorial @ index3.js:265 (anonymous) @ main.js:333 (anonymous) @ main.js:332 showTutorial @ WelcomePage.js:18643 (anonymous) @ main.js:350 bubble @ main.js:350 click_handler_1 @ WelcomePage.js:5582
To Reproduce
- Create an svelte app with 1 language i18n only and set it as fallback
- force locale to any other thing
- Check that the variables are not loading the fallback
Expected behavior Whichever string you add as locale, if it does not exist, fallback should be used instead.
Information about your project:
Built and tested with:
- Rollup
- Svelte Preprocess
- svelte-i18n v.3.3.7
- Mac Catalina
- Latest Chrome, Firefox, Safari.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Release in 3.3.8.
I think this change makes sense, at least for now. Let’s see what the future brings.
Nice, I cloned the project, built it, changed dist with my dist in node_modules and it works perfect for my case.