Improve fallback language handling #1927
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We currently have the use case to provide multiple locales (
de
,de-AT
,de-DE
,de-CH
) for one language (de
) without the need for individual translations. Preferably we would like to use a function forfallbackLng
, like(code) => code.split('-')[0]
, as we need to support a wide range of locales.When using
fallbackLng
like this, we still need to provide JSON files for each locale, although the translations forde-AT
are no different than forde
. This PR is an attempt to fix this and I think it is related to #1652, #1649 and #1465.Depending on the setup, the changes of this PR might add multiple fallback locales to
window.__NEXT_DATA__
. This could lead to increased page size. Should we add a notice about this in the docs?Additionally we could utilize the config
nonExplicitSupportedLngs
to automatically add fallbacks per locale (e.g.de
forde-AT
). If understood correctly, this would reduce setup complexity and remove the need ofserializeConfig: false
- because a function forfallbackLng
would no longer be necessary. Do you think this would be the expected behavior @adrai? Otherwise we could add a short notice to the docs, that this option is currently not supported with next-i18next as this was my first (incorrect) assumption. This might be related to #1412.I‘m quite new to the code base and very happy about feedback, alternative solutions or improvement suggestions for this PR. Thank you!
Checklist
npm run test