JFLib

plat/locale.rs#

Source: lib/plat/locale.rs

locale -- the user's languages and regional format as BCP 47 tags ("de-DE", "en-US")

  system_languages() -> Vec<String>   the UI languages in order of preference (empty: unknown)
  system_locale() -> Option<String>   the regional format of numbers and dates (None: unknown)
  locale_tag(s) -> Option<String>     "de_DE.UTF-8@euro" / "de-de" -> "de-DE"; "C", "POSIX"
                                      and empty -> None

Windows: GetUserPreferredUILanguages and GetUserDefaultLocaleName.  Linux, the browser and
Android: the environment -- LANGUAGE (a ':' list, GNU), LC_ALL, LC_MESSAGES, LANG for the
languages; LC_ALL, LC_TIME, LC_NUMERIC, LANG for the format.  The browser host sets LANGUAGE
from navigator.languages, the Android host from the system's locale list.  macOS and iOS:
CoreFoundation's preferred languages and current locale; LANGUAGE / LC_ALL / LC_MESSAGES and
LC_ALL / LC_TIME / LC_NUMERIC set by hand win (LANG alone does not).
  • fn locale_tag(s: &str) -> Option<String> a POSIX locale name or a BCP 47 tag as a BCP 47 tag: language lower case, a script title case, a region upper case ("zh_hant_tw" -> "zh-Hant-TW"); None for "C" / "POSIX" / empty

  • fn system_languages() -> Vec<String> the UI languages in order of preference (empty when the system names none)

  • fn system_locale() -> Option<String> the regional format (numbers, dates, currency) of the user

  • fn system_languages() -> Vec<String> (Apple) Apple: the system's preferred languages (CFLocaleCopyPreferredLanguages); LANGUAGE, LC_ALL or LC_MESSAGES set by hand win (LANG alone does not: Terminal sets it from the region)

  • fn system_locale() -> Option<String> (Apple) Apple: LC_ALL, LC_TIME or LC_NUMERIC set by hand, else the system's current locale (CFLocaleCopyCurrent: "de_DE", "en_US@rg=dezzzz" -> "en-US"), else LANG, else the first language

  • fn system_languages() -> Vec<String> (Windows) the UI languages in order of preference (empty when the system names none)

  • fn system_locale() -> Option<String> (Windows) the regional format (numbers, dates, currency) of the user

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