Skip to content
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

Improve fallback language handling #1927

Merged
merged 5 commits into from
Aug 16, 2022
Merged

Conversation

chrilis
Copy link
Contributor

@chrilis chrilis commented Aug 16, 2022

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 for fallbackLng, 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 for de-AT are no different than for de. 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 for de-AT). If understood correctly, this would reduce setup complexity and remove the need of serializeConfig: false - because a function for fallbackLng 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

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • commit message and code follows the Developer's Certification of Origin

@adrai
Copy link
Member

adrai commented Aug 16, 2022

I‘m also relatively new ;-)

lgtm

Regarding nonExplicitSupportedLngs I think this could be part of a separate PR, what do you think?

@chrilis
Copy link
Contributor Author

chrilis commented Aug 16, 2022

Yes, I'll be happy to write a separate PR for nonExplicitSupportedLngs. I guess I will start working on it after this PR is merged.

@adrai adrai merged commit 4007385 into i18next:master Aug 16, 2022
@chrilis chrilis deleted the fallback-languages branch August 20, 2022 05:52
@adrai
Copy link
Member

adrai commented Aug 21, 2022

included in v12.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants