Aller-Couleur / handlebars-i18n

handlebars-i18next.js adds the internationalization features of i18next and Intl to handlebars.js
Other
16 stars 6 forks source link

document how to change language base on user setting #20

Closed javadbat closed 3 years ago

javadbat commented 3 years ago

first of all, thank you for your effort you put to maintain this repo its help me a lot my question is how can I change the render language base on the user setting? in our project, we keep user language in our cookie, and in every request, we get it like this: image my question is how I can tell the handlebar to render the page base on lang variable thank you.

javadbat commented 3 years ago

to make my problem clear my current solution is this: image but as I think set i18next.changeLanguage(lang); is not a good idea because my whole node application language change on every request and it's CRAZY! I just want that specific request handled and rendered in lang and I don't want to change my entire i18n config for each request

fwalzel commented 3 years ago

I am not quite sure how this interacts with my module handlebars-i18n. What you could try if you have the user language stored in some variable like 'userLang' is to override the language of the generic request. Like so: {{__ myKey lng=userLang }}. This will always give you the value for the key in user’s selected language, no matter how the generic request is set. Not sure if this is what you are looking for …

andremetzen commented 3 years ago

@fwalzel I'm also having the same issue but on a different context (too long to explain here). The main issue here is that we can have multiple instance of i18next but handlebars-i18n always assume the instance getting it from require('i18next') here.

My suggestion is to allow override it passing the i18next instance to init() method.

fwalzel commented 3 years ago

Feature is now ready in v1.3.0. See readme.md under "Using custom instances of Handlebars"