Internationalization for Rust applications
| Tier | foundation |
| Role | unclassified (baselined) |
| Path | crates/foundation/i18n |
| Edition | 2021 |
| Targets | foundation_i18n |
| Public items | 47 across 0 modules |
| Tests | 30 |
What it is for
Internationalization library crates for Rust applications.
Provides translation management, locale handling, and pluralization support.
Capabilities
crate root
Internationalization library crates for Rust applications.
| Item |
|---|
fn get_plural_rules(locale : & Locale) -> Box <dyn PluralRules> |
ArabicPluralRules
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct ArabicPluralRules |
ArabicPluralRules :: fn select(& self, n : f64) -> PluralCategory |
EnglishPluralRules
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct EnglishPluralRules |
EnglishPluralRules :: fn select(& self, n : f64) -> PluralCategory |
I18n
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct I18n |
I18n :: fn new(default_locale : Locale) -> Self |
I18n :: fn with_fallback(mut self, enabled : bool) -> Self |
I18n :: fn add_bundle(& mut self, locale : & Locale, bundle : TranslationBundle) |
I18n :: fn default_locale(& self) -> & Locale |
I18n :: fn available_locales(& self) -> Vec <String> |
I18n :: fn t(& self, locale : & Locale, key : & str) -> Result <String> |
I18n :: fn t_plural(& self, locale : & Locale, key : & str, count : f64) -> Result <String> |
I18n :: fn t_with(& self, locale : & Locale, key : & str, vars : & HashMap <String, String>,) -> Result <String> |
I18n :: fn translate(& self, locale : & Locale, key : & str, count : Option <f64>, vars : & HashMap <String, String>,) -> Result <String> |
I18n :: fn default() -> Self |
I18nError
Internationalization library crates for Rust applications.
| Item |
|---|
pub enum I18nError |
Locale
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct Locale |
Locale :: fn new(language : impl Into <String>) -> Self |
Locale :: fn parse(s : & str) -> Result <Self> |
Locale :: fn with_region(mut self, region : impl Into <String>) -> Self |
Locale :: fn with_script(mut self, script : impl Into <String>) -> Self |
Locale :: fn tag(& self) -> String |
Locale :: fn fallbacks(& self) -> Vec <Locale> |
Locale :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
Locale :: fn default() -> Self |
Locale :: fn direction(& self) -> TextDirection |
MessageFormat
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct MessageFormat |
MessageFormat :: fn new(pattern : impl Into <String>) -> Self |
MessageFormat :: fn format(& self, args : & HashMap <String, String>) -> String |
PluralCategory
Internationalization library crates for Rust applications.
| Item |
|---|
pub enum PluralCategory |
PluralRules
Internationalization library crates for Rust applications.
| Item |
|---|
pub trait PluralRules |
Result
Internationalization library crates for Rust applications.
| Item |
|---|
pub type Result<T>: std::result::Result <T, I18nError> |
RussianPluralRules
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct RussianPluralRules |
RussianPluralRules :: fn select(& self, n : f64) -> PluralCategory |
TextDirection
Internationalization library crates for Rust applications.
| Item |
|---|
pub enum TextDirection |
Translation
Internationalization library crates for Rust applications.
| Item |
|---|
pub enum Translation |
Translation :: fn get(& self, count : Option <f64>, locale : & Locale) -> & str |
TranslationBundle
Internationalization library crates for Rust applications.
| Item |
|---|
pub struct TranslationBundle |
TranslationBundle :: fn new() -> Self |
TranslationBundle :: fn add(& mut self, key : impl Into <String>, value : impl Into <String>) |
TranslationBundle :: fn add_plural(& mut self, key : impl Into <String>, forms : HashMap <PluralCategory, String>) |
TranslationBundle :: fn get(& self, key : & str) -> Option <& Translation> |
TranslationBundle :: fn has(& self, key : & str) -> bool |
TranslationBundle :: fn len(& self) -> usize |
TranslationBundle :: fn is_empty(& self) -> bool |
TranslationBundle :: fn merge(& mut self, other : TranslationBundle) |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum I18nError | I18n errors. |
pub type Result<T>: std::result::Result <T, I18nError> | Result type for i18n operations. |
pub struct Locale | Represents a locale identifier (e.g., "en-US", "fr-FR"). |
Locale :: fn new(language : impl Into <String>) -> Self | Create a new locale from a language code. |
Locale :: fn parse(s : & str) -> Result <Self> | Parse a locale string (e.g., "en-US", "zh-Hans-CN"). |
Locale :: fn with_region(mut self, region : impl Into <String>) -> Self | Set the region. |
Locale :: fn with_script(mut self, script : impl Into <String>) -> Self | Set the script. |
Locale :: fn tag(& self) -> String | Get the full locale tag. |
Locale :: fn fallbacks(& self) -> Vec <Locale> | Get fallback locales for this locale. |
Locale :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
Locale :: fn default() -> Self | — |
pub enum PluralCategory | Plural category for pluralization rules. |
pub trait PluralRules | Plural rules for different languages. |
pub struct EnglishPluralRules | English plural rules (one/other). |
EnglishPluralRules :: fn select(& self, n : f64) -> PluralCategory | — |
pub struct RussianPluralRules | Russian plural rules (one/few/many/other). |
RussianPluralRules :: fn select(& self, n : f64) -> PluralCategory | — |
pub struct ArabicPluralRules | Arabic plural rules. |
ArabicPluralRules :: fn select(& self, n : f64) -> PluralCategory | — |
fn get_plural_rules(locale : & Locale) -> Box <dyn PluralRules> | Get plural rules for a locale. |
pub enum Translation | A single translation entry. |
Translation :: fn get(& self, count : Option <f64>, locale : & Locale) -> & str | Get the translation string. |
pub struct TranslationBundle | Translation bundle containing all translations for a locale. |
TranslationBundle :: fn new() -> Self | Create a new empty bundle. |
TranslationBundle :: fn add(& mut self, key : impl Into <String>, value : impl Into <String>) | Add a simple translation. |
TranslationBundle :: fn add_plural(& mut self, key : impl Into <String>, forms : HashMap <PluralCategory, String>) | Add a plural translation. |
TranslationBundle :: fn get(& self, key : & str) -> Option <& Translation> | Get a translation by key. |
TranslationBundle :: fn has(& self, key : & str) -> bool | Check if a key exists. |
TranslationBundle :: fn len(& self) -> usize | Get the number of translations. |
TranslationBundle :: fn is_empty(& self) -> bool | Check if the bundle is empty. |
TranslationBundle :: fn merge(& mut self, other : TranslationBundle) | Merge another bundle into this one. |
pub struct I18n | Internationalization context. |
I18n :: fn new(default_locale : Locale) -> Self | Create a new i18n context. |
I18n :: fn with_fallback(mut self, enabled : bool) -> Self | Set whether fallback is enabled. |
I18n :: fn add_bundle(& mut self, locale : & Locale, bundle : TranslationBundle) | Add a translation bundle for a locale. |
I18n :: fn default_locale(& self) -> & Locale | Get the default locale. |
I18n :: fn available_locales(& self) -> Vec <String> | Get available locales. |
I18n :: fn t(& self, locale : & Locale, key : & str) -> Result <String> | Translate a key. |
I18n :: fn t_plural(& self, locale : & Locale, key : & str, count : f64) -> Result <String> | Translate a key with count for pluralization. |
I18n :: fn t_with(& self, locale : & Locale, key : & str, vars : & HashMap <String, String>,) -> Result <String> | Translate a key with variables. |
I18n :: fn translate(& self, locale : & Locale, key : & str, count : Option <f64>, vars : & HashMap <String, String>,) -> Result <String> | Full translation with all options. |
I18n :: fn default() -> Self | — |
pub struct MessageFormat | Message format for complex translations. |
MessageFormat :: fn new(pattern : impl Into <String>) -> Self | Create a new message format. |
MessageFormat :: fn format(& self, args : & HashMap <String, String>) -> String | Format the message with arguments. |
pub enum TextDirection | Direction of text for a locale. |
Locale :: fn direction(& self) -> TextDirection | Get the text direction for this locale. |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier foundation with 27 other crates: foundation-audit-log, foundation-basemodels, foundation-bounded-io, foundation-conversation-closure, foundation-crypto-sign, foundation-decisioning, foundation-encounter-vocabulary, foundation-fs-metadata, … (27 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | foundation |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/foundation/i18n |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full | no | always |
Build. None.
Depended on by. 2 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_i18n["application-i18n"] -->|uses| SELF n_identity_user_prefs["identity-user-prefs"] -->|uses| SELF SELF["foundation-i18n"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | foundation_i18n | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
I18nError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
2 workspace crates depend on this one: application-i18n, identity-user-prefs.
Verification
| Kind | Count |
|---|---|
| Unit tests | 30 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 14 | 0 | 5 |
What the tests establish, by name:
test_arabic_plural_rules—src/lib.rstest_english_plural_rules—src/lib.rstest_get_plural_rules_by_language—src/lib.rstest_i18n_available_locales—src/lib.rstest_i18n_fallback—src/lib.rstest_i18n_interpolation—src/lib.rstest_i18n_key_not_found—src/lib.rstest_i18n_no_fallback—src/lib.rstest_i18n_plural—src/lib.rstest_i18n_simple_translation—src/lib.rstest_locale_direction_ltr—src/lib.rstest_locale_direction_rtl—src/lib.rstest_locale_display—src/lib.rstest_locale_fallbacks—src/lib.rstest_locale_fallbacks_english—src/lib.rstest_locale_new—src/lib.rstest_locale_parse_invalid—src/lib.rstest_locale_parse_simple—src/lib.rstest_locale_parse_underscore—src/lib.rstest_locale_parse_with_region—src/lib.rstest_locale_parse_with_script—src/lib.rstest_locale_tag—src/lib.rstest_locale_with_region—src/lib.rstest_message_format—src/lib.rstest_russian_plural_rules—src/lib.rstest_translation_bundle_add—src/lib.rstest_translation_bundle_merge—src/lib.rstest_translation_bundle_plural—src/lib.rstest_translation_plural_get—src/lib.rstest_translation_simple_get—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 41 | 47 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 41
"No rustdoc detected" : 6
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 793 |
| Code lines | 601 |
| Public API items | 47 |
| Public modules | 0 |
| Tests | 30 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 3 |
| Workspace reverse dependencies | 2 |
pie showData
title Public API by kind
"enum" : 4
"function" : 1
"method" : 33
"struct" : 7
"trait" : 1
"type alias" : 1
pie showData
title Rust source composition
"Code" : 601
"Blank or comment" : 192
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.