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§
- Chained
Backend - A backend that chains multiple backends together.
- Flat
Backend - Generic in-memory translation storage.
- I18n
- The core i18n runtime.
- I18n
Builder - Builder for constructing an
I18ninstance. - Locale
- A parsed locale identifier.
- Toml
Backend - A compile-time-embeddable TOML translation backend.
Enums§
- I18n
Error - i18n error type
- Plural
Category - 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
I18ninstance. - interpolate
- Replace
%{name}placeholders in a template string with provided values. - negotiate_
locale - Negotiate the best available locale from an
Accept-Languageheader value. - plural_
category - Determine the plural category for a given locale and count.
- set_
global - Set the global
I18ninstance used by thet!macro. - task_
locale - Get the current task-local locale, if set.