@ocisp87 any time
Setting the language - server-side / client-side
-
Is there a way to set the NodeBB language in either the server or client js?
I have a cookie that contains the language code I want to set the forum to.
Is there a hook I can use on the server-side to set the language, or equally something on the client side I can use to change the locale?
Is there a way I can hook into the User's 'language' selector options to roll my own solution?
Note: passing
?lang=[LANGAUGE]
in the URL isn't an option
Note: Using the User settings isn't an option as I need to set the language before this point, from a CookieIs there a way to read cookies in the
middleware.autoLocale
function? (src/middleware/headers.js) req.cookies = {} at this point.
However, inside thefunction translate(str, req, res, next) {
req.cookies is a full object as I expect (src/middleware/render.js)Thanks!
-
@danlong you can override the userLang in
filter:config.get
, BTW noticereq.query.lang
in there, that's how?lang=
works. -
@PitaJ Perfect, thank you. That's done the trick
-
@PitaJ Does config.userLang set the language for guests? Or is that a different property?
-
@danlong I believe it applies to all users
-
@PitaJ OK, I'll check it again - it seems to change the timedate for guests, nothing else gets translated. It's only logged-in users which seem to be effected by the
config.userLang
Passing the
?lang=
for a guest doesn't seem to work either -
@PitaJ I think I have a very edge-case scenario, I've found a solution for guests and logged in users.
Thanks for your help and point in the right direction!