Running an app under specific locale "formats"

I know you can use
export LANG=xx_XX.UTF8
to run a program under specific locale, but regional settings in Linux/Ubuntu also feature "Formats" option.

Is there a way to run an app under specific locale and formats (en_US and en_GB respectively) for testing purposes, without affecting system-wise settings?

Follow-up question: how can I dump all ENV variables/setup under which the specific process is running?

Asked By: Digika

||

Is there a way to run an app under specific locale and formats (en_US
and en_GB respectively) for testing purposes, without affecting
system-wise settings?

Yes, you can set environment variables on the commandline itself before the program’s name/command like LANG for example with gedit:

LANG=en_US.UTF-8 gedit

… and that will set that environment variable specifically and only for that certain program i.e gedit during that certain session/run … However, the chosen language should be both supported by and installed for that certain program for this to work.

Other local/regional formats, however, can be explicitly set separately each has its own specific environment variable like for example LC_MEASUREMENT, LC_TIME, LC_NUMERIC, LC_MONETARY … etc. and you can set as many of those as you need in the same way like for example:

LANG=en_US.UTF-8 LC_MEASUREMENT=en_GB.UTF-8 LC_NUMERIC=en_GB.UTF-8 gedit

How can I dump all ENV variables/setup under which the specific
process is running?

Assuming a currently running process … That is in /proc/PID/environ where PID is the actual running process’s ID.

Taking gedit as an example program, those can be dumped (in Bash) for example like so:

(gedit & disown) &>/dev/null; cat /proc/$(pgrep 'gedit')/environ

… those, however, are NUL/zero delimited entries and, for readability, you might want to parse them into separate lines by for example piping the output to xargs like so:

(gedit & disown) &>/dev/null; cat /proc/$(pgrep 'gedit')/environ |
xargs -0 -n1

Notice that while most commandline programs will honor all the explicitly set commandline locale environment variables and the global environment variables otherwise, this is not the case with GUI programs … Simple GUI programs and DE shipped programs (like Gnome apps for example) will most likely honor those environment variable likewise, but more complex/independent programs like web-browsers for example will most likely have their own internal configuration files that are set inside their UI and will ignore external duplicate environment settings and accept others that are not internally set …

As an example, the FireFox web-browser only accepts setting the user interface language from within its preferences menu in the UI and saves it as an entry called intl.locale.requested that will look something like user_pref("intl.locale.requested", "en-US,ar"); and that is saved in a file called prefs.js inside the active profile’s directory i.e. for the SNAP version that would be in ~/snap/firefox/common/.mozilla/firefox/0qag4e79.default/prefs.js for example … And therefore the LANG or LANGUAGE locale environment variables are ignored whether globally set or explicitly set on the commandline … However, other locale related environment variables like LC_MEASUREMENT, LC_TIME, LC_NUMERIC and LC_MONETARY are still honored (in both cases) as it appears until now, so you can set those ones explicitly on the commandline if you wish and expect them to both be reflected in /proc/PID/environ and take effect as well when applicable.

Answered By: Raffa