-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow rejection of attempted load via returning falsy loadPath #88
Conversation
How does your i18next config look like? |
Vue.use(VueI18Next);
i18next.use(i18nextXHR);
i18next.init({
whitelist: AvailableLocales.locales,
fallbackLng: 'en-us',
lowerCaseLng: true,
backend: {
loadPath: 'static/locales/{{lng}}.json',
// allow cross domain requests
crossDomain: false,
// allow credentials on cross domain requests
withCredentials: false,
},
interpolation: {
// We let vuejs handle HTML output escaping
escapeValue: false,
},
});
// Build in the english translation so it can be used as a fallback
i18next.addResourceBundle('en-us', 'translation', FallbackLocale); App plugins adding all their translations at once (intended if only a few translations) would use Once a new namespace has been created changing the language results in each namespace trying to load, which for namespaces added by the plugins the loadPath is not correct but still loads translations. Hope that better explains why I would like this feature |
This looks like an "add after init" setup: https://www.i18next.com/how-to/add-or-load-translations#combined-with-a-backend-plugin Try these options:
btw: the whitelist option is deprecated / removed => supportedLngs |
I dont believe that is going to solve my issue, adding resources is working fine. its when changing the language im forced to return a url for every namespace regardless if one exists or not, hopefully this screenshot will help explain the console logs are coming from
|
Yes, if the namespace for a specific language has not been loaded (nor added via addResourceBundle or similar), it will try to load it via configured backend plugin. btw: Does it create any problem when a namespace is requested, that is not provided via backend plugin? it's just a 404, right? This should not influence your app?
if this is true, they will not be requested again, because the resources are already present in i18next's internal store |
The plugins namespace might not have a translation for that language at all or a url to lazy load it. But currently I am force to return a url in loadPath, if I just return the default namespaces lazy load path when no other exists it result in loading that language twice |
I don't think so, they will not be requested again, because the resources are already present in i18next's internal store. Can you please provide a simple reproducible example that shows this behaviour? |
If they are not in the store and I have no url for that namespace my only option is to load the default namespaces translations into the new namespace, or intentionally return a url that cannot be reached |
like suggested, just add |
but that would stop the default namespace from loading its translations from 'static/locales/{{lng}}.json' |
extended the example with plugin-{small,large} |
Ok for your setup none of this options is needed. It only loads the translations that are not present in the i18next store (so not yet loaded) For fr the translation namespace and the plugin-large namespace are not loaded, that's why they get loaded |
in your changes make the change language to 'de' The main app may support languages the plugin never will (plugin would fallback to en-us) |
ahhh so there are inconsistencies between your supportedLngs in your main app and the plugins? |
yes and not provide a url to obtain other langs |
strange setup, but ok... |
we have support for plugins within a single html file (somewhat like vue.js single file component). plugins having their own i18next instance would only really work if all plugins where webpacked |
https://www.i18next.com/overview/api#cloneinstance would not need any sort of packaging... but ok... |
Plugins having their own instances would add a lot of confusion in vue templates where we have a mixin to provide $t('namespace:key') access to i18next for reactive translations (they all update when the language changes) I will push returning {} change shortly, I have also made a note of |
Thanks, your time has been greatly appreciated |
v1.4.0 is the version you are looking for ;-) If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project. There are many ways to help this project 🙏 |
Reasoning for feature
As part of the plugin system for the web app I'm working on, I would like to provide the ability for plugins to provide all their translations at once or a url path to their json translation files.
When providing all the translations at once, changing language results in the default namespace's translations also being loaded in to the plugins namespace. (due to static loadPath)
To solve these issues I would like to be able to stop a translation download if a url is not stored for the loading namespace
How I intend to use this feature within the web app: