Skip to main content

Module i18n

Module i18n 

Source
Expand description

Message language. Messages are written in English; a Japanese translation is shown when the language is Japanese.

  • Language: set_lang (the GUI setting), otherwise LENSBENCH_LANG (ja・en), otherwise the OS language (Japanese if it starts with ja, English otherwise).
  • Translation: a table (the computing crates’ one is lang/ja.tsv of the lensbench-lang crate, which the entry points add with add_table at start-up; it is kept out of this crate so that adding a line does not rebuild every crate that depends on the core) holds English template<TAB>Japanese template. A {...} in the English template matches any text, and the same {...} in the Japanese template is replaced by that text (identical tokens such as {} are taken in order). Only the text slots {e} (a nested message), {why}・{hint} (an added note) and {what} (a label) are translated again; other slot values (names, numbers, file names) are kept as they are. Only {e} and {why} may hold ": ". When several lines match, the one with the most literal text wins. A message that is not in the table is split at ": " and each part is translated (the context added by crate::Error::at); text with no match stays as is.
  • New messages: write them in English and add the Japanese line to lensbench-lang/lang/ja.tsv. Crates outside this repository’s public part keep their own table and add it with add_table.

Enums§

Lang
Message language

Functions§

add_table
Add a table of the same format as lensbench-lang/lang/ja.tsv (the entry points add that table, and an exe that adds plugins adds the Japanese of their messages, at start-up; the text is read when it is first needed). Check it with check_table in a test
check_table
Check a table: each line has a tab, the same {…} in English and Japanese, unnamed {} in the same order, no two slots side by side, and no English twice. The errors name the line
is_ja
Whether messages are shown in Japanese
lang
The current message language
set_lang
Choose the message language (the GUI calls this when its language changes)
tr
The message in the current language (English as written, Japanese from the table)
tr_doc
translate_doc in the current language
tr_item
translate_item in the current language
translate
The Japanese of an English message (the whole message, otherwise each ": "-separated part, otherwise, when every sentence has a line, each sentence: a note of several sentences joined by ". " becomes sentences joined by “。”)
translate_doc
Japanese of a description of several lines (help, analysis settings): each line from its own table line (a trailing [unit] is kept as it is); lines with no line of their own stay English
translate_item
The Japanese of a name from an # items section of the table (a tolerance item such as L1 group decenter x); other text stays as it is
warning
A warning line for the terminal: “warning: …” in English, “注意: …” (translated) in Japanese