Skip to main content

Crate waterui_locale

Crate waterui_locale 

Source
Expand description

§WaterUI i18n

Internationalization (i18n) support for WaterUI applications.

§What it does

Always available:

  • Type-safe locales: Using ICU4X for locale identifiers
  • CLDR plural rules: Proper pluralization for all languages
  • Smart fallback: zh-TW → zh-Hant → zh (not zh-Hans!)
  • LocalizedDisplay: Trait for locale-aware formatting

Behind a cargo feature, because each carries its own slice of CLDR data:

  • number: format_number, format_percent, format_currency, the unit wrappers (Length<Meter>, Temperature<Celsius>, …) that render through them, and the numeric interpolation text! performs
  • datetime: format::date, the locale-aware date and time formatters
  • list: LocalizedList, locale-aware list conjunction

§Usage

Application text goes through waterui’s text! macro, which resolves translations and CLDR plural categories against the effective locale:

use waterui::prelude::*;

// With en: "I have 5 apples"
// With zh: "我有5个苹果"
text!("I have {#count} apple")

This crate is the runtime underneath it: locale identification and fallback, plural-category selection, and locale-aware formatting.

use waterui_locale::{PluralCategory, locales, select_plural};

assert_eq!(select_plural(&locales::EN, &1), PluralCategory::One);
assert_eq!(select_plural(&locales::EN, &5), PluralCategory::Other);

Re-exports§

pub use catalog::TranslationCatalog;
pub use format::LocalizedDisplay;
pub use locale::Locale;
pub use locale::locales;
pub use plural::select_plural;
pub use plural::valid_categories;

Modules§

catalog
Runtime translation catalog loaded from app-provided i18n tables.
format
Locale-aware formatting utilities.
locale
Locale types and constants using ICU4X.
parser
TOML translation file parser.
plural
CLDR plural rules using ICU4X.
regional
Shared locale runtime for WaterUI.

Enums§

PluralCategory
Re-export PluralCategory from ICU4X. The plural categories are used to format messages with numeric placeholders, expressed as decimal numbers.

Functions§

layout_direction
Returns the Unicode layout direction for a locale.
layout_direction_computed
Returns a reactive layout direction derived from the effective locale.
locale_binding
Returns a reactive binding for the effective locale in the given environment.
start_system_locale_listener
Starts delivering system locale changes to locale-aware views.