i18next / i18next-browser-languageDetector

language detector used in browser environment for i18next
MIT License
865 stars 88 forks source link

Add ability to specify mapping function #273

Closed olliechick closed 1 year ago

olliechick commented 1 year ago

🚀 Feature Proposal

Add the ability to specify a mapping function.

Motivation

To allow customising the language code before returning it.

Example

Using Transifex, language codes need to use underscores (e.g. en_US), not dashes (e.g. en-US), but browsers set the language code with dashes. To get around this, it would be good to be able to specify a function that replaces dashes with underscores.

adrai commented 1 year ago

Why not use a tms that has full support for i18next, like locize.com, and at the same time you support the future of i18next? You already said it, the browser uses the locale standard BCP 47 (https://www.i18next.com/how-to/faq#how-should-the-language-codes-be-formatted)

olliechick commented 1 year ago

My company is already using Transifex and it would be difficult to move off it

olliechick commented 1 year ago

In the meantime, as a workaround, I have reimplemented all the detectors from https://github.com/i18next/i18next-browser-languageDetector/tree/master/src/browserLookups but changed them to do the mapping of - to _.

adrai commented 1 year ago

v7.1.0

image