pub struct Locale { /* private fields */ }Expand description
零堆、16 字节 Copy BCP-47 语言区域标签(支持 language[-Script][-REGION],兼容 #![no_std] 常量表)。
示例:Locale::EN_US(en-US)、Locale::ZH_CN(zh-CN)、Locale::ZH_TW(zh-TW)、Locale::JA_JP(ja-JP)、Locale::AR_SA(ar-SA)。
Implementations§
Source§impl Locale
impl Locale
Sourcepub const fn from_lang_region(lang: &str, region: &str) -> Self
pub const fn from_lang_region(lang: &str, region: &str) -> Self
编译期构造 language-REGION 形式的 Locale(如 "zh", "CN" -> zh-CN)。
Sourcepub const fn from_parts(lang: &str, script: &str, region: &str) -> Self
pub const fn from_parts(lang: &str, script: &str, region: &str) -> Self
编译期构造完整 language-Script-REGION 形式的 Locale(如 "zh", "Hans", "CN")。
Sourcepub fn parse(raw: &str) -> Option<Self>
pub fn parse(raw: &str) -> Option<Self>
解析 BCP-47 或 POSIX 风格语言标签(兼容 "zh_CN.UTF-8"、"zh-Hans-CN"、"en-us"、"ja")。
若输入为空或不包含有效 ASCII 字母语言子标签,返回 None。
Sourcepub const fn without_script(self) -> Self
pub const fn without_script(self) -> Self
去除脚本子标签(如 zh-Hans-CN -> zh-CN)。
Sourcepub const fn language_only(self) -> Self
pub const fn language_only(self) -> Self
退化为纯语言码(如 zh-CN -> zh),用于 BCP-47 层级回退查找。
Sourcepub const fn same_language(self, other: Self) -> bool
pub const fn same_language(self, other: Self) -> bool
判断两个 Locale 的主语言码是否一致(忽略地区与脚本差异)。
Sourcepub fn text_direction(self) -> TextDirection
pub fn text_direction(self) -> TextDirection
根据主语言码返回默认书写方向(ar / he / iw / fa / ur / ps / sd / yi -> TextDirection::Rtl)。
Sourcepub fn format_tag<'b>(&self, buf: &'b mut [u8; 16]) -> &'b str
pub fn format_tag<'b>(&self, buf: &'b mut [u8; 16]) -> &'b str
将规范化 BCP-47 标签零堆写入调用方提供的 16 字节栈缓冲区并返回切片(如 "zh-CN")。
Sourcepub fn native_short_name(self) -> &'static str
pub fn native_short_name(self) -> &'static str
返回当前语言友好的原生短标签(供工具栏语言切换按钮显示)。
Sourcepub fn plural_category(self, count: i64) -> PluralCategory
pub fn plural_category(self, count: i64) -> PluralCategory
按 Unicode CLDR 整数复数规则计算 count 所属的 PluralCategory。
Trait Implementations§
impl Copy for Locale
impl Eq for Locale
impl StructuralPartialEq for Locale
Auto Trait Implementations§
impl Forget for Locale
impl Freeze for Locale
impl Move for Locale
impl RefUnwindSafe for Locale
impl Send for Locale
impl Sync for Locale
impl Unpin for Locale
impl UnsafeUnpin for Locale
impl UnwindSafe for Locale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。