moui_i18n

    Pure target-neutral internationalization addon for MoUI

    moui
    i18n
    localization
    translation
    Download zip
    Author
    Version
    0.6.2
    License
    Apache-2.0
    Last updated
    10 hours ago
    Downloads
    475

    No dependencies

    wzzc-dev/moui_i18n does not have a README file

    CalendarDate

    pub(all) struct CalendarDate {
    year : Int
    month : Int
    day : Int
    }

    A validated proleptic Gregorian calendar date for numeric formatting.

    CalendarDate::new

    fn CalendarDate::new(year~ : Int, month~ : Int, day~ : Int) -> CalendarDate?

    Creates a calendar date, rejecting years outside 0..=9999, months outside 1..=12, and days outside the month's length (including leap-year rules).

    Catalog

    pub struct Catalog {
    messages : Map[String, Map[String, String]]
    }

    An in-memory catalog indexed by canonical locale and message key.

    Catalog::from_entries

    fn Catalog::from_entries(entries : ArrayView[Message]) -> Catalog

    Builds a catalog from static message entries. Entries with invalid locale identifiers are ignored. Later entries replace earlier entries with the same locale and key.

    Locale

    pub struct Locale {
    language : String
    script : String?
    region : String?
    }

    A normalized locale identifier consisting of a language and optional script and region subtags.

    Locale::canonical

    fn Locale::canonical(self : Locale) -> String

    Returns the canonical locale string, such as zh-Hans-CN.

    Locale::fallback_candidates

    fn Locale::fallback_candidates(self : Locale) -> Array[String]

    Returns deterministic lookup candidates from most to least specific. A locale with both script and region falls back through language-script and then language.

    Locale::format_date

    fn Locale::format_date(self : Locale, date : CalendarDate) -> String

    Formats a date in the locale's numeric field order and separator, with a four-digit year and zero-padded month and day: 11/09/2026 for en-US, 09.11.2026 for de, 2026/11/09 for ja. Unlisted locales use the ISO-style 2026-11-09 order.

    Locale::format_int

    fn Locale::format_int(self : Locale, value : Int64) -> String

    Formats an integer with locale-aware digit grouping, such as 1,234,567 for en, 1.234.567 for de, and 12,34,56,789 for en-IN.

    Locale::format_number

    fn Locale::format_number(self : Locale, value : Double, fraction_digits? : Int) -> String

    Formats a number with locale-aware grouping and decimal separators, such as 1,234.5 for en, 1.234,5 for de, and 1 234,5 (narrow no-break space) for fr. fraction_digits defaults to 2 and is clamped to 0..=15; rounding is half up on the absolute value. The scaled magnitude must fit in Int64. NaN and infinities render as NaN, ∞, and -∞.

    Locale::language

    fn Locale::language(self : Locale) -> String

    Returns the canonical language subtag.

    Locale::parse

    fn Locale::parse(raw : String) -> Locale?

    Parses a locale identifier with a language and optional script and region. Both - and _ separators are accepted. Canonical locale casing uses a lowercase language, titlecase script, and uppercase region.

    Locale::plural_category

    fn Locale::plural_category(self : Locale, count : Int) -> PluralCategory

    Selects the CLDR cardinal plural category for an integer count, using the absolute value of the count. Rules follow the CLDR supplemental plural data (https://unicode.org/repos/cldr/trunk/specs/ldml/tr35-numbers.html#Language_Plural_Rules). Fractional and compact-notation operands are out of scope; languages without a dedicated rule use the root other category.

    Locale::region

    fn Locale::region(self : Locale) -> String?

    Returns the canonical region subtag when supplied.

    Locale::script

    fn Locale::script(self : Locale) -> String?

    Returns the canonical script subtag when supplied.

    Message

    pub(all) struct Message {
    locale : String
    key : String
    value : String
    }

    A static translation entry in a catalog.

    Message::new

    fn Message::new(locale~ : String, key~ : String, value~ : String) -> Message

    Constructs a static translation entry.

    PluralCategory

    pub(all) enum PluralCategory {
    Zero
    One
    Two
    Few
    Many
    Other
    } derive(Eq,
    Debug
    )

    A CLDR cardinal plural category.

    PluralCategory::equal

    PluralCategory::key

    fn PluralCategory::key(self : PluralCategory) -> String

    Returns the catalog key suffix for this category, such as one or other.

    PluralCategory::not_equal

    fn PluralCategory::not_equal(x : PluralCategory, y : PluralCategory) -> Bool

    Translator

    pub struct Translator {
    catalog : Catalog
    locale : Locale
    default_locale : Locale
    }

    Resolves messages from a catalog using requested and default locale fallback candidates.

    Translator::new

    fn Translator::new(catalog~ : Catalog, locale~ : Locale, default_locale~ : Locale) -> Translator

    Creates a translator for a catalog, requested locale, and default locale.

    Translator::translate

    fn Translator::translate(self : Translator, key : String, values? : ArrayView[(String, String)]) -> String

    Translates a message key and interpolates named values. Missing messages return a nonfatal [[key]] marker.

    Translator::translate_count

    fn Translator::translate_count(self : Translator, key : String, count : Int, values? : ArrayView[(String, String)]) -> String

    Translates a plural message using the CLDR cardinal plural category for the requested locale (see Locale::plural_category). When the selected category variant is absent, the .other variant is used. The count value is always available as the {count} placeholder.