Replies: 1 comment 4 replies
-
please read the docs https://www.i18next.com/overview/configuration-options#languages-namespaces-resources -> what supportedLngs is used for (not what is loaded - but what is allowed to load <-- you provide the complete list)... https://www.i18next.com/overview/api#hasresourcebundle <- check if there is data for lng, ns https://github.com/i18next/i18next/blob/master/src/ResourceStore.js#L158 <- check lng has some data accessing |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Following on from this question I asked, I've kept digging and I am pretty sure this feature doesn't seem to actually exist.
I suggest adding a new value to the i18next API:
i18next.availableLanguages
. This will list the current range of languages for which resources are loaded, such that callingi18next.changeLanguage(code)
with a code from that list will produce a translation using a resource file for that language.Consider the following scenario in which I initialise my application:
This setup (with no supportedLngs attribute) now supports switching to any language that might be available, but the only available languages are en, de, and tlh.
During runtime I download some updates from the server for new language support:
The list of available languages is now
["en", "de", "ko", "jp", "it", "es", "pt"]
. If I were to present a language switcher to the user, I would want to provide that exact list of options. However, there isn't a trivial way to ask i18next for this list.If I want to have this information I have to separately track what I've added and removed, but that is a secondary source of truth and may or may not reflect what is actually made available by i18next right this moment. I want to consult i18next itself as the source of truth on what it can do here.
The closest equivalent I've found so far is to look at the keys on the resourceStore's data:
This seems hacky though and not like the right way to do this. Hence more directly providing this information via the i18next instance as
i18next.availableLanguages
.Beta Was this translation helpful? Give feedback.
All reactions