Skip to main content

Crate anycms_i18n

Crate anycms_i18n 

Source
Expand description

§anycms-i18n

Internationalization support for the anycms-rs ecosystem.

§Quick Start

use anycms_i18n::{I18nBuilder, t};

let i18n = I18nBuilder::new()
    .default_locale("en")
    .fallback_locale("en")
    .embedded_translations(&[
        ("en", include_str!("../../locales/en.toml")),
        ("zh-CN", include_str!("../../locales/zh-CN.toml")),
    ])
    .build()
    .unwrap();

// Simple translation
let msg = t!("welcome");

// With locale override
let msg = t!("welcome", locale = "zh-CN");

// With interpolation
let msg = t!("greeting", name = "world");

// With plural
let msg = t!("items", count = 5);

Macros§

__t_inner
Internal helper used by t!. Not part of the public API.
embed_locales
Compile-time embedding helper.
i18n
Initialize i18n with compile-time embedded translations.
t
Translate a key using the global i18n instance.

Structs§

ChainedBackend
A backend that chains multiple backends together.
FlatBackend
Generic in-memory translation storage.
I18n
The core i18n runtime.
I18nBuilder
Builder for constructing an I18n instance.
Locale
A parsed locale identifier.
TomlBackend
A compile-time-embeddable TOML translation backend.

Enums§

I18nError
i18n error type
PluralCategory
CLDR plural categories.

Statics§

CURRENT_LOCALE
Task-local locale, set by web framework middleware.

Traits§

Backend
Translation backend trait.
Reloadable
Trait for backends that support runtime reloading (hot-reload).

Functions§

global
Get a reference to the global I18n instance.
interpolate
Replace %{name} placeholders in a template string with provided values.
negotiate_locale
Negotiate the best available locale from an Accept-Language header value.
plural_category
Determine the plural category for a given locale and count.
set_global
Set the global I18n instance used by the t! macro.
task_locale
Get the current task-local locale, if set.