JFLib

ui/i18n_locale.rs#

Source: lib/ui/i18n_locale.rs

i18n_locale -- regional formats (a compact subset of CLDR) and plural categories

  Locale::get(tag) -> Locale          the best match of a BCP 47 tag: the tag itself, the
                                      language with the region, the language's default
                                      ("de" -> de-DE, "en" -> en-US), else "en-001"
  locale() / set_locale(tag) / locale_tag()   the user's format: ui boots it from
                                      jfgui_LANG, the system (window mode) or "de-DE"
                                      (headless runs, so shots match on every machine)
  loc.fmt_int(n)                      "1.234.567" (de), "1,234,567" (en), "12,34,567" (hi)
  loc.fmt_num(v, decimals)            fixed decimals, rounded; grouped
  loc.fmt_percent(fraction, decimals) 0.25 -> "25 %" (de), "25%" (en), "%25" (tr)
  loc.fmt_currency(v, "USD") / fmt_money(v)   "1.234,56 $" (de), "$1,234.56" (en-US);
                                      fmt_money in the locale's own currency
  loc.fmt_size(bytes)                 "1,5 MB" (1024 based; French "Mo")
  loc.fmt_date(&civil, DATE_SHORT | DATE_LONG) / fmt_time(&civil) / fmt_date_time(&civil)
                                      "17.10.2026" / "17. Oktober 2026" / "19:58";
                                      en-US "10/17/2026" / "October 17, 2026" / "7:58 PM"
  loc.first_weekday() (0 = Monday .. 6 = Sunday), rtl(), decimal(), group(), currency(), tag()
  fmt_int / fmt_num / fmt_percent / fmt_currency / fmt_money / fmt_size / fmt_date /
  fmt_time / fmt_date_time            the same with locale()
  plural(lang, i, v, f) / plural_int(lang, n) -> Plural   CLDR cardinal categories (i the
                                      integer digits, v the number of visible fraction
                                      digits, f those digits as an integer)

Numbers use ASCII digits everywhere (also Arabic and Hindi); spaces inside numbers and
before units are no-break spaces (U+00A0, French U+202F).  Long dates use the format
(genitive) month names of the locale's language.
/// fmt_date: "17.10.2026" / "10/17/2026"
DATE_SHORT: u32 = 0
/// fmt_date: "17. Oktober 2026" / "October 17, 2026"
DATE_LONG: u32 = 1
  • struct Locale the formats of one region (copy it freely)

impl Locale

  • fn get(tag: &str) -> Locale the best match of a BCP 47 tag or a POSIX locale name (see the module comment)

  • fn tag(&self) -> &'static str the tag of the matched data ("de-DE", "en-001")

  • fn decimal(&self) -> char the decimal sign

  • fn group(&self) -> char the thousands separator

  • fn first_weekday(&self) -> u32 the first day of the week: 0 = Monday .. 6 = Sunday

  • fn rtl(&self) -> bool right-to-left script (Arabic, Hebrew)

  • fn currency(&self) -> &'static str the ISO 4217 code of the region's currency

  • fn month_name(&self, m: u32) -> &'static str the long (format) name of month m (1..12) in the locale's language

  • fn fmt_int(&self, n: i64) -> String an integer with group separators

  • fn fmt_num(&self, v: f64, decimals: u32) -> String a number with exactly decimals fraction digits (rounded) and group separators

  • fn fmt_percent(&self, fraction: f64, decimals: u32) -> String a fraction as percent: 0.25 -> "25 %" (de) / "25%" (en)

  • fn fmt_currency(&self, v: f64, code: &str) -> String an amount of the ISO 4217 currency code ("EUR", "USD"; unknown codes are shown as is)

  • fn fmt_money(&self, v: f64) -> String an amount in the region's own currency

  • fn fmt_size(&self, bytes: u64) -> String a byte count: "512 B", "1,5 KB", "23 MB" (1024 based, one decimal below 10)

  • fn fmt_date(&self, c: &Civil, style: u32) -> String a date: DATE_SHORT "17.10.2026" / DATE_LONG "17. Oktober 2026"

  • fn fmt_time(&self, c: &Civil) -> String a time of day: "19:58" / "7:58 PM"

  • fn fmt_date_time(&self, c: &Civil) -> String the short date and the time: "17.10.2026, 19:58" / "10/17/2026, 7:58 PM"

  • fn locale() -> Locale the user's regional format (default "de-DE")

  • fn locale_tag() -> String the tag the format was asked for ("de-LU" may use the data of "de-DE")

  • fn set_locale(tag: &str) set the user's regional format (a BCP 47 tag or a POSIX locale name)

  • fn fmt_int(n: i64) -> String Locale::fmt_int in the user's format

  • fn fmt_num(v: f64, decimals: u32) -> String Locale::fmt_num in the user's format

  • fn fmt_percent(fraction: f64, decimals: u32) -> String Locale::fmt_percent in the user's format

  • fn fmt_currency(v: f64, code: &str) -> String Locale::fmt_currency in the user's format

  • fn fmt_money(v: f64) -> String Locale::fmt_money in the user's format

  • fn fmt_size(bytes: u64) -> String Locale::fmt_size in the user's format

  • fn fmt_date(c: &Civil, style: u32) -> String Locale::fmt_date in the user's format

  • fn fmt_time(c: &Civil) -> String Locale::fmt_time in the user's format

  • fn fmt_date_time(c: &Civil) -> String Locale::fmt_date_time in the user's format

  • enum Plural a CLDR plural category

    • Zero
    • One
    • Two
    • Few
    • Many
    • Other

impl Plural

  • fn name(self) -> &'static str the CLDR keyword: "zero", "one", "two", "few", "many", "other"

  • fn plural_int(lang: &str, n: i64) -> Plural the plural category of an integer in a language ("de", "ru-RU", ...)

  • fn plural(lang: &str, i: u64, v: u32, f: u64) -> Plural the plural category of a number: i = its integer digits, v = the number of visible fraction digits, f = those digits as an integer ("1,50": i 1, v 2, f 50)

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