Request for comments: set LANG from HTTP Accept-Language

35 views
Skip to first unread message

Beuc

unread,
Jun 11, 2019, 3:57:23 PM6/11/19
to emscripten-discuss
Hi,

I issued a PR to expose the user's preferred language as ENV['LANG']:
https://github.com/emscripten-core/emscripten/pull/8751

It's based on navigator.languages which reflects HTTP Accept-Language, e.g.:
- HTTP Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
- navigator.languages = Array(4) [ "fr", "fr-FR", "en-US", "en" ]
- ENV['LANG'] = fr.UTF-8

(Currently Emscripten uses a hard-coded 'C.UTF-8'.)

This PR allows starting your WebAssembly program directly using the
user's preferred language (rather than shoving a language choice in
their face on start-up ;)).
Provided your program is i18n'd / multi-language, of course.
For nodejs no changes.

While this environment variable is pretty standard on desktop, Alon
expressed concerned that this may be risky to start doing this now.

Hence we moved the discussion to this list :)
What do you think?

Cheers!
Beuc

キャロウ マーク

unread,
Jun 11, 2019, 4:57:53 PM6/11/19
to emscripten-discuss


On Jun 11, 2019, at 12:57, Beuc <be...@beuc.net> wrote:

This PR allows starting your WebAssembly program directly using the
user's preferred language (rather than shoving a language choice in
their face on start-up ;)).
Provided your program is i18n'd / multi-language, of course.
For nodejs no changes.

While this environment variable is pretty standard on desktop, Alon
expressed concerned that this may be risky to start doing this now.

Hence we moved the discussion to this list :)
What do you think?

I would love it if you did it and developers paid attention to it. However I wouldn’t bet on anyone paying attention. I’m fed up with web sites that ignore my language preferences and serve a web page in the language of the place I happen to be. That seems to be the predominant and completely bogus modus-operandi among web sites these days. Of course they’re happy to remember your language preference *if* you let them set a cookie.

Regards

    -Mark



signature.asc

Floh

unread,
Jun 12, 2019, 5:26:02 AM6/12/19
to emscripten-discuss
What about a html5.h function to poll the language:

const char* emscripten_get_navigator_language(void);

Would this provide enough functionality while being less "intrusive"?

I don't know how the ENV-variable approach affects C runtime functions though,
but for showing a UI in the user's preferred language this would probably
suffice (as a user I guess I'd still like to have an additional "in-app-option" to 
change the language though).

Beuc

unread,
Jun 12, 2019, 6:06:23 AM6/12/19
to emscripte...@googlegroups.com

Hi,

This PR's point is improving the "standard-ness" of the Emscripten environment :)
(One could easily make yet another emscripten-specific change and grab 'navigator.languages' using EM_JS.)

With this PR, for instance, my RenPyWeb port can use Python's 'locale' package without any changes.
Programs using gettext(3) would also work as-is.

LANG doesn't affect the C runtime until the program calls setlocale(3) (cf. PR discussion).
This is about language preference detection; changing the language in-app (sadly) cannot be solved at this level ;)

Cheers!
Beuc

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/acc93acd-b423-41f9-995b-b870d02c58dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Beuc

unread,
Jun 26, 2019, 2:40:18 AM6/26/19
to emscripte...@googlegroups.com

Hi,

FYI the PR was accepted :)

Cheers!
Beuc

Reply all
Reply to author
Forward
0 new messages