JFLib

ui/i18n_msg.rs#

Source: lib/ui/i18n_msg.rs

i18n_msg -- messages with named, numbered and plural placeholders (a subset of ICU
MessageFormat), so translations may reorder and inflect

  msg(text, &[("n", 3.into()), ("dir", "Bilder".into())]) -> String

  {name} {0} {}            an argument by name, by position, or the next one in order;
                           numbers as they are, with the locale's decimal sign ("1234,5")
  {n, number}              grouped ("1.234,5"); styles: integer (rounded), percent (a
                           fraction: 0.25 -> "25 %"), currency/EUR, size (bytes: "1,5 MB")
  {d, date} {d, date, long} {d, time} {d, datetime}   an Arg::Date (datetime::Civil)
  {n, plural, =0 {keine Dateien} one {# Datei} other {# Dateien}}
                           the CLDR category of the UI language (language_code()); =N
                           matches before the categories; # is the number (grouped);
                           "offset:1" before the options subtracts 1 for # and the category
  {g, select, female {sie} male {er} other {es}}
  '{' '}' '#' quote,  '' is an apostrophe; a lone apostrophe stays ("geht's")

The numbers follow the user's format (locale()).  A missing argument prints as {name};
broken syntax prints the rest of the text as it is.
  • enum Arg<'a> one argument of msg()

    • Str(&'a str)
    • Int(i64)
    • Num(f64)
    • Date(Civil)
  • fn msg(text: &str, args: &[(&str, Arg)]) -> String format a message (see the module comment)

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