Skip to content

Internationalization

Level: 201 · working knowledge

One line: std has no locale — to_uppercase is the same everywhere, {} formats 1234.5 identically in every country, and < sorts by code point — so translating messages, plural rules, number formats and collation all come from crates.

Stub — an outline, not a lesson. There is no runnable example behind this page yet, so nothing on it has been through the check that backs every other claim in this library. The bullets below are the questions the finished page has to answer.

What it has to cover

  • What std deliberately does without a locale: format!, to_uppercase, cmp on str — each shown producing the same output regardless of the machine's settings
  • Messages and plurals: Project Fluent (fluent), gettext-rs, rust-i18n — how each stores translations and how each handles "1 file" versus "2 files" in a language with more plural forms
  • Numbers, dates and currencies: ICU4X (the icu crate) with CLDR data, and num-format for the narrow case
  • Collation: why sorting German or Polish words by < is wrong, and ICU4X's collator — link comparing and sorting text
  • Case: the Turkish dotted and dotless i, and why to_lowercase cannot know which you meant
  • Where the locale comes from on each OS, and why a server should take it from the request rather than from LANG

The trap it exists for

Formatting user-facing numbers with format!("{:.2}") and concatenating translated fragments ("You have " + n + " messages"). The first ignores the decimal separator, and the second hard-codes English word order and plural rules into every language.

Where this sits

The string crates lists the crates by job. This page is the i18n job specifically. Comparing and sorting text is where byte order stops being enough.

See also

If you are coming from another language

Po polsku

Biblioteka standardowa Rusta nie ma pojęcia ustawień regionalnych (locale): format! wypisze 1234.5 tak samo w Polsce i w USA, a < posortuje „ćma” za „dom”, bo porównuje kody znaków, a nie polski alfabet. Tłumaczenia komunikatów, formy liczby mnogiej, formaty liczb i sortowanie językowe (collation) dają dopiero skrzynie — fluent, icu (ICU4X).

Szukaj po polsku: internacjonalizacja · lokalizacja aplikacji · sortowanie polskich znaków · rust i18n fluent · icu4x collator rust