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

feat: allow browser language detection #371

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

isaacknjama
Copy link
Contributor

Resolves #350

This PR allows i18next to detect the language set in the user's browser and translate the page.

Translation happens seamlessly now.

@isaacknjama isaacknjama requested a review from a team as a code owner February 8, 2024 19:21
Copy link
Collaborator

@wbobeirne wbobeirne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I just realized that #350 isn't about spanish not activating, it's about some translations missing in spanish. This is currently a manual process, so not all of the keys in english have spanish counterparts. It falls back to english, so you see english in those cases. This is not a configuration issue.

@isaacknjama
Copy link
Contributor Author

isaacknjama commented Feb 9, 2024

Ah I just realized that #350 isn't about spanish not activating, it's about some translations missing in spanish. This is currently a manual process, so not all of the keys in english have spanish counterparts. It falls back to english, so you see english in those cases. This is not a configuration issue.

While working on this, I noticed translation doesn't happen automatically with the browser language setting - this is on Chrome(Brave, Chromium). Modifying the i18NextLng key in localStorage manually causes the page to get translated to the value set. Hence, the addition of the detection config to update this key according to browser language setting.

@wbobeirne
Copy link
Collaborator

wbobeirne commented Feb 9, 2024

Based on what I'm seeing in the README for that project, it will use the navigator but only after checking the other sources. It looks like it saves a LS key based on the initial detected language from navigator, then uses that going forward. So if you change your browser language settings, it will still use the old one based on the key that was saved.

I think it would be wise to retain this behavior in the future, if we want to add a language selector. Perhaps you should just empty out the caches: [] option instead, to not save it to the cache, but to keep the configuration to check for a LS key: https://github.com/i18next/i18next-browser-languageDetector/blob/9efebe6ca0271c3797bc09b84babf1ba2d9b4dbb/src/index.js#L20

@isaacknjama
Copy link
Contributor Author

Based on what I'm seeing in the README for that project, it will use the navigator but only after checking the other sources. It looks like it saves a LS key based on the initial detected language from navigator, then uses that going forward. So if you change your browser language settings, it will still use the old one based on the key that was saved.

I think it would be wise to retain this behavior in the future, if we want to add a language selector. Perhaps you should just empty out the caches: [] option instead, to not save it to the cache, but to keep the configuration to check for a LS key: https://github.com/i18next/i18next-browser-languageDetector/blob/9efebe6ca0271c3797bc09b84babf1ba2d9b4dbb/src/index.js#L20

This makes sense, took me a while to get the logic! Thanks for pointing this out.

@Kodylow Kodylow merged commit f5e8216 into fedimint:master Feb 12, 2024
1 check passed
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.

spanish translations not working everywhere
3 participants