JFLib

Languages#

Source: lib/ui/i18n.rs

i18n -- languages, translation catalogues, regional formats and messages

  set_language(LANG_*) / language()   the UI language: the catalogue column (process wide;
                                      default German, the source column)
  set_language_code(code) -> index    the best column for a BCP 47 code ("fr-CA" -> "fr",
                                      else English, else the source)
  language_code() -> "de" / "en" / ...   the code of the current column
  user_languages() / set_user_languages(list)   the languages the user wants, in order (ui
                                      boots them from --lang or jfgui_LANG, the system in
                                      window mode, "de-DE" in headless runs);
                                      negotiate(available, wanted)
  use_system()                        user languages and format from --lang, jfgui_LANG or
                                      the system (programs without ui::main!)
  tr(de) -> text                      a text of the library itself (file dialog, command
                                      bar, tree, toasts, shortcuts, date picker) in the UI
                                      language: German, English, French, Spanish, Italian,
                                      Dutch, Polish, Arabic, Hebrew (library_languages), else
                                      English; the German source text is the key
                                      (library_keys)
  Catalog::from_tsv(text)             an app's catalogue: a TSV file whose first line names
                                      the languages ("de\ten\tfr"), then one row per text,
                                      the source text first; catalog.tr(s) -> the text in
                                      the current language (the source when missing)
  month_name(m) / month_short(m) / weekday_short(d)   calendar names of the UI language
                                      (m 1..12, d 0 = Mon)
  Catalog::with_library_languages()   also offer the languages of the library's own texts;
                                      the app's texts show their English column in them
  set_catalog(catalog) / t(s)         the app's catalogue for the whole process: t(s) is the
                                      text in the current language (the library's text, then
                                      the English column, then the German source when the
                                      cell is missing).  Unless set_language came first, the
                                      column is negotiated with the user's languages
  commands(table) / menu(table)       a static command table or menu in the current language
                                      (a copy made once per table and language)
  fill(text, args)                    "{}" placeholders replaced in order
  tf(s, args) / list(&TABLE)          t with its "{}" filled; a table of texts through t
  msg(text, args)                     named / numbered placeholders, plurals, select,
                                      numbers and dates in the user's format (i18n_msg.rs)
  locale(), Locale, fmt_*, plural     regional formats and plural rules (i18n_locale.rs)
  collate(a, b), Collator, to_upper / to_lower / fold, eq_ignore_case   sorting by language
                                      and case mapping (i18n_collate.rs)

The language index is the catalogue column: LANG_DE = 0 (the source column), LANG_EN = 1.
LANG_DE: u32 = 0
LANG_EN: u32 = 1
  • fn set_language(lang: u32) set the UI language: the catalogue column (LANG_DE, LANG_EN, ...)

  • fn language_code() -> String the code of the current UI language ("de", "en", "fr"; the catalogue's header, lower case)

  • fn set_language_code(code: &str) -> u32 select the column that fits a BCP 47 code best (the language, else English, else the source) -> its index; a later catalogue is matched with the code again

  • fn negotiate<A: AsRef<str>, W: AsRef<str>>(available: &[A], wanted: &[W]) -> Option<usize> the first of available that fits the wanted languages (in their order): the same tag, else the same language ("fr-CA" takes "fr" or "fr-FR")

  • fn user_languages() -> Vec<String> the languages the user wants, most wanted first (BCP 47)

  • fn set_user_languages<W: AsRef<str>>(list: &[W]) set the user's languages; an installed catalogue follows unless set_language came first

  • fn use_system() the user's languages and format from jfgui_LANG ("fr-CA" or a ':' list), else the system

  • fn rtl_language() -> bool whether the UI language is written right to left (Arabic, Hebrew, Persian, Urdu, ...): ui mirrors its windows then (Ui::set_rtl)

  • fn language() -> u32 the current UI language (LANG_*)

  • fn tr(de: &'static str) -> &'static str a library text in the current language: the UI language when the library has it (library_languages), else English; the German source when the text is not in the table

  • fn library_languages() -> &'static [&'static str] the languages of the library's own texts (tr, month_name, weekday_short): "de", "en", "fr", "es", "it", "nl", "pl", "ar", "he"

  • fn library_keys() -> impl Iterator<Item = &'static str> the German source texts of the library's own texts (the keys of tr)

  • fn month_name(m: u32) -> &'static str the name of month m (1..12) in the current language

  • fn month_short(m: u32) -> &'static str the short name of month m (1..12)

  • fn weekday_short(d: u32) -> &'static str the two-letter name of weekday d (0 = Monday .. 6 = Sunday)

  • fn weekday_abbr(d: u32) -> &'static str the usual abbreviation of weekday d (0 = Monday) in running text: "Sa" / "Sat"

  • struct Catalog a translation catalogue of an app (see the module comment)

impl Catalog

  • fn from_tsv(text: &'static str) -> Catalog parse a TSV catalogue (first line: the language codes); "\n" and "\t" escapes in the cells are not interpreted

  • fn with_library_languages(mut self) -> Catalog also offer the languages of the library's own texts (library_languages): there the library's texts follow the user and Arabic and Hebrew mirror the window, while the app's own texts show their English column. The browser bundle has no font for Arabic and Hebrew: there they stay out, the user gets English instead of empty boxes

  • fn languages(&self) -> &[String] the language codes of the columns ("de", "en", ...)

  • fn tr<'a>(&'a self, s: &'a str) -> &'a str the text in the current language (the source text when the cell is missing or empty)

  • fn has(&self, s: &str) -> bool whether the catalogue has a row for this source text

  • fn set_catalog(c: Catalog) install the app's catalogue for the whole process (t() reads it); its column follows the user's languages unless set_language (the same column) or set_language_code (the best column for that code) came first

  • fn t(s: &'static str) -> &'static str the app's text in the current language: the installed catalogue, then the library's own texts, then the catalogue's English column, then the German source

  • fn commands(src: &'static [Command]) -> &'static [Command] a command table (static, German) in the current language, made once per table and language

  • fn menu(src: &'static [Mi]) -> &'static [Mi] a menu (static, German) in the current language, made once per menu and language

  • fn tf(s: &'static str, args: &[&str]) -> String the app's text in the current language with its "{}" placeholders filled in order

  • fn list(items: &[&'static str]) -> Vec<&'static str> a table of the app's texts in the current language (combo boxes, tabs)

  • fn fill(text: &str, args: &[&str]) -> String replace the "{}" placeholders of a text in order

impl Catalog

  • fn get_static(&self, s: &str) -> Option<&'static str> the translation of a source text in the current language, when the catalogue has one

Source: docs/API.md in the JFLib repository.