L17N of programs

Date: 2023/04/28 (initial publish), 2023/09/02 (last update)

Source: en/note-00042.md

Previous Post Top Next Post

TOC

The most annoying L10N problem for me as ja user is the font variant selection. zh_CN seems to be chosen as Asian font variant default for en_US environment. This prompted me to summarize tips here.

L10N mechanism

L10N (localization) of programs written with proper I18N (internationalization) may be controlled by the values of environment variables.

According to setlocale(3), for glibc based programs, effective locale values are set for each category as:

According to info gettext "The LANGUAGE variable", LANGUAGE value sets priority list of translated languages. If LANG is set to C, this is ignored.

The current values of such environment variables on the default en_US system can be checked from shell prompt as:

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

These values are effective inside of the locale command.

The tricky thing is Bash only exports LANG and LANGUAGE and the locale command sets other variable values inside it. See variables exported.

$ export -p|grep -E -e  '(LC_|LANG)'
declare -x GDM_LANG="en_US.UTF-8"
declare -x LANG="en_US.UTF-8"
declare -x LANGUAGE="en_US:en"

L10Ned execution of program from shell prompt

For changing locale environment of program, you only need to change and export LANG and LANGUAGE variables to the program to be executed.

Here, LANG is respected by many programs while LANGUAGE seems to be respected only by programs using GNU Gettext system.

I check actual situation by invoking program as follows:

$ LANG=ja_JP.UTF-8 program_name
$ LANG=en_US.UTF-8 LANGUAGE=ja program_name

My cursory checks yielded:

The locale setting not only changed messages produced by programs but also changed default values such as the default font set used by the GUI program.

In case of gnucash, the default currency was controlled by LANG.

Normal way to change L10N

For GNOME, normal way to change L10N is:

The negative of this approach is this requires logout.

Custom L10Ned execution without logout for CLI

This is least invasive and easy to manage from CLI.

The use shell alias can be used to execute program under an arbitral L10N environment without logout and without changing the main system environment.

alias jo="LANG=ja_JP.UTF-8 libreoffice"
alias jw="LANG=ja_JP.UTF-8 lowriter"
alias jc="LANG=ja_JP.UTF-8 LANGUAGE=ja gnucash"
alias jc="LANGUAGE=ja google-chrome-stable"

If above alias settings are included in ~/.bashrc, typing jo starts “LibreOffice” under more or less desirable Japanese settings including font choice (No zh_CN oriented gliphs) and typing jc starts “GNuCash” under more or less desirable Japanese settings including JPY as currency and account entry names in Japanese.

Custom L10Ned execution without logout for GUI (via desktop)

This is least invasive and easy to manage from GUI.

Create a jgnucash.desktop file as follows based on /usr/share/applications/gnucash.desktop with minor changes and place it in ~/local/share/applications/.

[Desktop Entry]
Type=Application
MimeType=application/x-gnucash;
Version=0.9.4
Name=JGnuCash
GenericName=Finance Management (日本語環境)
Comment=Manage your finances, accounts, and investments in Japanese
Exec=env LANG=ja_JP.UTF-8 LANGUAGE=ja gnucash %f
# Translators: Icon file name, do not translate unless you also provide a localized icon file. Alternatively use the English "gnucash-icon" as msgstr
Icon=gnucash-icon
StartupNotify=true
Terminal=false
Categories=Office;Finance;
X-GNOME-Bugzilla-Bugzilla=gnucash.org
X-GNOME-Bugzilla-Product=GnuCash
X-GNOME-Bugzilla-Component=General
X-GNOME-Bugzilla-Version=4.13
X-GNOME-DocPath=gnucash-help/gnucash-help.xml
X-GNOME-FullName=GnuCash Finance Management

Please note that if you use gnucash.desktop as the filename here, your normal English GnuCach desktop provided by /usr/share/applications/gnucash.desktop becomes hidden from the GUI session.

Custom L10Ned execution without logout for GUI (invasive)

This is a deprecated approach for me since this is too invasive.

Let’s make a GUI program gnucash started from GUI globally under Japanese environment ja_JP.UTF-8 while keeping your system under en_US.UTF-8.

Simple use of sudo mv /usr/bin/gnucash /usr/bin/gnucash.orig isn’t robust against package update. Here, dpkg-divert must be used, instead.

 $ cd /usr/bin
 $ sudo tee gnucash.orig << EOF
LANG="ja_JP.UTF-8" LANGUAGE=ja /usr/bin/gnucash.orig
EOF
 $ sudo chown 755 gnucash.ja
 $ sudo dpkg-divert --local --rename --divert /usr/bin/gnucash.orig --add /usr/bin/gnucash
 $ sudo ln -sf gnucash.ja gnucash

Here wrapper gnucash.ja is used to start gnucash under Japanese environment.

With this set up, one can switch among different environment by changing symlink.

You can restore the original state as:

 $ rm gnucash
 $ sudo dpkg-divert --local --rename --remove /usr/bin/gnucash

Set default in all applications of Libreoffice

It took me a while to find a way to set default initial values in all applications of Libreoffice (7.4). Here are how for each application:

I came to the above from corresponding tips in 2014.

Saving template with the configuration may be a trick to make these changes persistent.

Pre-template default font settings across all applications seem to be accessible. Under LibreOffice 7.4, the same can be done as:

TBH, this “Advanced” trick is too complicated for me. So I decided to keep myself away from this.

Set default page size in Libreoffice

Libreoffice doesn’t seem to respect the setting in /etc/papersize set by paperconf(1). Follow Libreoffice wiki.

CUPS configuration may be performed via browser pointing to http://localhost:631/.

L10N for displayed page of web content by the browser

Displayed page of web content by the browser can be set independent of GUI dialog language set by LANG.

For Chrome, click “customize and control” at the top-right corner to display “Settings”. Then click “Languages” and configure “Preferred languages”.

Previous Post Top Next Post