GNU TeXmacsUser manualReferenceAboutEnglish
Translation of the interface and locales

1.Dictionaries

struct dictionary_rep: rep<dictionary>
(a translation table)

Declared in

System/Language/dictionary.hpp

. A dictionary translates strings from one language from into another to; it is a resource named from-to, created by load_dictionary (from, to) and kept for the session. Its table maps source strings to translations.

Dictionaries are loaded from the files from-to.scm in the search path $TEXMACS_DIC_PATH, which consists of $TEXMACS_HOME_PATH/langs/natural/dic, $TEXMACS_PATH/langs/natural/dic and the

langs/natural/dic

directories of the plug-ins (

System/Boot/init_texmacs.cpp

). All matching files are loaded, so a plug-in or the user can add entries. Each file is a sequence of pairs

("Bibtex command" "commande Bibtex")

For some target languages (Chinese, Japanese, Korean, Taiwanese, Russian, Ukrainian, Bulgarian, German, Greek, Slovak) the translations are stored in UTF-8 and converted to Cork when loaded; for the others the files must be in the Cork encoding, which coincides with ISO-8859-1 for most accented letters. Only english-lan.scm files exist; if a dictionary lan-english is requested and no file exists, it is built by inverting english-lan.

dictionary_rep::translate (s, guess) looks for a translation in this order:

  1. the string itself;

  2. the string with its first letter in lower case (the translation then gets an upper case first letter);

  3. the part before a :: marker: a string such as "Ctrl::keyboard" is translated as "Ctrl", but may have its own entry, which allows to disambiguate homonyms;

  4. if guess is set, the string is split: leading and trailing non letters (such as ":", "…" or a number) are translated separately, with a space before :, ! and ? in French, and otherwise the string is split at its last non letter which is not a space;

  5. failing all this, the string is returned unchanged.

2.The translation interface

The output language is a global variable of

dictionary.cpp

, set with set_output_language and read with get_output_language. At the Scheme level, set-output-language is bound to gui_set_output_language (

Texmacs/Server/tm_server.cpp

), which also refreshes all menus and widgets. It is called when the language preference changes (notify-language in

texmacs/texmacs/tm-server.scm

), whose default is the language of the user's locale (get-locale-language).

The main functions are

translate (s), translate

Translate a string from English into the output language.

translate (s, from, to), translate-from-to

Translate between two given languages.

translate_as_is, string-translate

The same without guessing.

tree_translate (t), tree-translate

Translate all strings of a tree which are accessible children according to the current DRD, except inside verbatim. Two tags are special: localize translates its argument from English into the output language, whatever the from and to arguments, and (replace pattern arg1 …) translates the pattern without guessing and substitutes the translated arguments for %1, %2, …. The Scheme function replace (

language/natural.scm

) builds and translates such a tree.

translate (t) for a tree

Translate the tree and serialize it as a string, as needed for window titles and native menus; keyboard shortcuts (render-key) are rendered in a GUI dependent way.

Menus and widgets call these functions themselves: every label of a menu or widget is a string or tree in English, translated when the widget is built.

Documents use the same dictionaries through the typesetting primitive translate (edit_env_rep::exec_translate,

Typeset/Env/env_exec.cpp

). The macro localize of

std-utils.ts

is defined as <translate|text|english|<value|language>>, so that the automatically generated texts of a document (“Chapter”, “Theorem”, …) follow the document language rather than the language of the interface.

3.Maintaining the dictionaries

Two Scheme modules help translators:

language/natural.scm

In developer mode, the menu and widget macros of

kernel/gui/gui-markup.scm

record every label in the table all-translations. tr-missing lists the labels seen so far that have no translation, and tr-rebuild rewrites the dictionary file with the missing entries added. The commands are in the translations submenu of the developer menu.

utils/misc/translation-list.scm

A more systematic approach: update-translatable collects all translatable strings from the Scheme sources into

english-new.scm

(minus those in

english-ignore.scm

), update-missing computes, for each language, the list of missing translations in src/TeXmacs/langs/natural/miss/english-lan-miss.scm, and translate-begin / translate-end export these lists for an online translation service and merge the results back.

4.Locales and dates

System/Language/locale.cpp

converts between TeXmacs language names and system locales:

get_locale_language ()

The language of the user, from LC_ALL, LC_MESSAGES, LANG or GDM_LANG, from the system settings on macOS, or from the user interface language on Windows; English by default.

locale_to_language (s)

From a locale such as fr_FR.UTF-8 to french, using the first two letters, with special cases for en_GB and zh_TW.

language_to_locale (s)

The converse, used to choose spell checking dictionaries, to build the language parameter sent to LanguageTool and to format dates.

get_locale_charset ()

The character set of the system: UTF-8 on Windows, macOS, Haiku, Android and with the X11 toolkit, and otherwise the value reported by nl_langinfo.

get_date (lan, fm), pretty_time, pretty_date

Dates in a given language and format. With Qt they are computed by Qt (

Plugins/Qt/qt_utilities.cpp

); otherwise date is run with the locale of the language.

5.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".