martinkr/next-export-i18n

Language autodétection

Closed this issue · 8 comments

Hello, looking at the code and implementing it, and I wonder if there is a language autodetection feature because it always takes my defaultLang as language despite the French language on the browser for example.
Thanks

Hi TiavinaRakotobe,

thank you for your contribution.

Currently there is no auto detection. I'm acutally implenting a feature which checks if there is a langage pack which matches the browser language and uses this as default language.

Hopefully, it will be available next week.

Cheers!

@martinkr thank you for your instant response

@martinkr Is there an option to disable this? I'd like to enforce the default language regardless of the user's browser settings. Some languages aren't available on browsers (or they came preinstalled with English and users do not know how to change it).

Hi @laymonage,

Thank you for reaching out.
Currently no. You could use the previous version (1.2.x).

I'm not sure I understand you concern, can you elaborate on your issue?
Maybe it's just a misunderstanding.

Let me guide you through the implementation:
1.) you define all available translations of your code
2.) you define the default language for your translation (the one which is used in case the user did not select anything)
3.) the package reads the browser language settings and checks if it is available in your translations (step 1) ). If it is, use this one instead of the default language you specified( step 2). Otherwise - the browser's default lang is not available in the translations - use the default language you set initially (step 2)

Cheers!

Thanks for the explanation! I understand how it works, but what happens if:

  1. I provide translations for English and Balinese (just for the sake of this example).
  2. The website is mostly targeted towards people who speak Balinese, so I set the default language to Balinese.
  3. There's no Balinese language support in most browsers, so users are likely to use another language for the browser (e.g. English).
  4. Now the default language of the website for the users becomes English, which is not what I'm aiming for.

This also happens if the user just happens to be using the browser in English (e.g. the browser comes preinstalled with the laptop, and it's set to English) and they're not tech-savvy enough to know how to change it.

Hi @laymonage,

I see! Thank you for the explanation - going to implement the option next week.
Until then, please use 1.2.x.

Cheers!

No rush, and thank you very much for the useful package!