foundation tier

foundation-i18n

Internationalization for Rust applications

Internationalization for Rust applications

Tierfoundation
Roleunclassified (baselined)
Pathcrates/foundation/i18n
Edition2021
Targetsfoundation_i18n
Public items47 across 0 modules
Tests30

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`

ItemWhat it is
pub enum I18nErrorI18n errors.
pub type Result<T>: std::result::Result <T, I18nError>Result type for i18n operations.
pub struct LocaleRepresents a locale identifier (e.g., "en-US", "fr-FR").
Locale :: fn new(language : impl Into <String>) -> SelfCreate 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>) -> SelfSet the region.
Locale :: fn with_script(mut self, script : impl Into <String>) -> SelfSet the script.
Locale :: fn tag(& self) -> StringGet 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 PluralCategoryPlural category for pluralization rules.
pub trait PluralRulesPlural rules for different languages.
pub struct EnglishPluralRulesEnglish plural rules (one/other).
EnglishPluralRules :: fn select(& self, n : f64) -> PluralCategory
pub struct RussianPluralRulesRussian plural rules (one/few/many/other).
RussianPluralRules :: fn select(& self, n : f64) -> PluralCategory
pub struct ArabicPluralRulesArabic 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 TranslationA single translation entry.
Translation :: fn get(& self, count : Option <f64>, locale : & Locale) -> & strGet the translation string.
pub struct TranslationBundleTranslation bundle containing all translations for a locale.
TranslationBundle :: fn new() -> SelfCreate 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) -> boolCheck if a key exists.
TranslationBundle :: fn len(& self) -> usizeGet the number of translations.
TranslationBundle :: fn is_empty(& self) -> boolCheck if the bundle is empty.
TranslationBundle :: fn merge(& mut self, other : TranslationBundle)Merge another bundle into this one.
pub struct I18nInternationalization context.
I18n :: fn new(default_locale : Locale) -> SelfCreate a new i18n context.
I18n :: fn with_fallback(mut self, enabled : bool) -> SelfSet 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) -> & LocaleGet 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 MessageFormatMessage format for complex translations.
MessageFormat :: fn new(pattern : impl Into <String>) -> SelfCreate a new message format.
MessageFormat :: fn format(& self, args : & HashMap <String, String>) -> StringFormat the message with arguments.
pub enum TextDirectionDirection of text for a locale.
Locale :: fn direction(& self) -> TextDirectionGet 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)
Locationcrates/foundation/i18n
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
serde^1derivenoalways
serde_json^1noalways
thiserror^2noalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1fullnoalways

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

KindNameSource
libfoundation_i18n`src/lib.rs`

Error model

Error typeNamed by
I18nErrorResult

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone 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.

2 workspace crates depend on this one: application-i18n, identity-user-prefs.

Verification

KindCount
Unit tests30
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root1405

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc4147
Public modules with a //! block00
pie showData
    title Public items with rustdoc
    "Documented" : 41
    "No rustdoc detected" : 6

Metrics

MetricValue
Rust source files1
Source lines793
Code lines601
Public API items47
Public modules0
Tests30
Examples0
Cargo features0
Direct runtime dependencies3
Workspace reverse dependencies2
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.

All foundation · Manual