Skip to main content

Module i18n

Module i18n 

Source
Expand description

国际化(i18n)支持 — Fluent FTL 消息翻译 + ICU4X 本地化格式化。

提供两大能力:

  1. 消息翻译I18nManager + tr):基于 Fluent FTL 消息文件, 支持中英文切换,系统语言环境自动检测。
  2. 本地化格式化I18nFormatter):ICU4X 驱动的数字/日期/复数/排序格式化。

§启动初始化

在应用启动时调用 I18nManager::init 自动检测系统语言环境:

use trait_kit::i18n::I18nManager;

let mgr = I18nManager::init();

或使用指定 locale:

use trait_kit::i18n::I18nManager;

let mgr = I18nManager::init_with_locale("zh-CN").expect("zh-CN locale");

Structs§

I18nFormatter
基于 ICU4X 编译数据的 locale 感知格式化器。
I18nManager
Fluent 消息翻译管理器。

Enums§

I18nError
国际化操作返回的错误类型。

Functions§

tr
便捷函数:翻译消息 key。