Struct veloren_client_i18n::LocalizationGuard
source · pub struct LocalizationGuard {
pub(crate) active: AssetReadGuard<Language>,
pub(crate) fallback: Option<AssetReadGuard<Language>>,
}
Expand description
RAII guard returned from LocalizationHandle::read()
, resembles
[AssetGuard
]
Fields§
§active: AssetReadGuard<Language>
§fallback: Option<AssetReadGuard<Language>>
Implementations§
source§impl LocalizationGuard
impl LocalizationGuard
sourcepub fn try_fallback_msg(&self, key: &str) -> Option<Cow<'_, str>>
pub fn try_fallback_msg(&self, key: &str) -> Option<Cow<'_, str>>
Get a localized text from the given key in the fallback language.
sourcepub fn try_msg(&self, key: &str) -> Option<Cow<'_, str>>
pub fn try_msg(&self, key: &str) -> Option<Cow<'_, str>>
Get a localized text from the given key
First lookup is done in the active language, second in the fallback (if present).
sourcepub fn get_msg(&self, key: &str) -> Cow<'_, str>
pub fn get_msg(&self, key: &str) -> Cow<'_, str>
Get a localized text from the given key
First lookup is done in the active language, second in the fallback (if present). If the key is not present in the localization object then the key itself is returned.
sourcepub fn try_msg_ctx<'a>(
&'a self,
key: &str,
args: &'a FluentArgs<'_>,
) -> Option<Cow<'static, str>>
pub fn try_msg_ctx<'a>( &'a self, key: &str, args: &'a FluentArgs<'_>, ) -> Option<Cow<'static, str>>
Get a localized text from the given key using given arguments
First lookup is done in the active language, second in the fallback (if present).
sourcepub fn get_msg_ctx<'a>(
&'a self,
key: &str,
args: &'a FluentArgs<'_>,
) -> Cow<'static, str>
pub fn get_msg_ctx<'a>( &'a self, key: &str, args: &'a FluentArgs<'_>, ) -> Cow<'static, str>
Get a localized text from the given key using given arguments
First lookup is done in the active language, second in the fallback (if present). If the key is not present in the localization object then the key itself is returned.
sourcepub fn try_variation(&self, key: &str, seed: u16) -> Option<Cow<'_, str>>
pub fn try_variation(&self, key: &str, seed: u16) -> Option<Cow<'_, str>>
NOTE: Exists for legacy reasons, avoid.
Get a localized text from the variation of given key
First lookup is done in the active language, second in the fallback (if present).
sourcepub fn get_variation(&self, key: &str, seed: u16) -> Cow<'_, str>
pub fn get_variation(&self, key: &str, seed: u16) -> Cow<'_, str>
NOTE: Exists for legacy reasons, avoid.
Get a localized text from the variation of given key
First lookup is done in the active language, second in the fallback (if present). If the key is not present in the localization object then the key itself is returned.
sourcepub fn try_variation_ctx<'a>(
&'a self,
key: &str,
seed: u16,
args: &'a FluentArgs<'_>,
) -> Option<Cow<'_, str>>
pub fn try_variation_ctx<'a>( &'a self, key: &str, seed: u16, args: &'a FluentArgs<'_>, ) -> Option<Cow<'_, str>>
NOTE: Exists for legacy reasons, avoid.
Get a localized text from the variation of given key with given arguments
First lookup is done in the active language, second in the fallback (if present).
pub(crate) fn get_content_for_lang( lang: &Language, content: &Content, ) -> Result<String, String>
sourcepub fn get_content(&self, content: &Content) -> String
pub fn get_content(&self, content: &Content) -> String
Tries its best to localize compound message.
§Example
Content::Localized { "npc-speech-tell_site", seed, {
"dir" => Content::Localized("npc-speech-dir_north", seed, {})
"dist" => Content::Localized("npc-speech-dist_very_far", seed, {})
"site" => Content::Plain(site)
}}
npc-speech-tell_site =
.a0 = Have you visited { $site }? It's just { $dir } of here!
.a1 = You should visit { $site } some time.
.a2 = If you travel { $dist } to the { $dir }, you can get to { $site }.
.a3 = To the { $dir } you'll find { $site }, it's { $dist }.
npc-speech-dir_north = north
# ... other keys
npc-speech-dist_very_far = very far away
# ... other keys
- Because content we want is localized itself and has arguments, we iterate over them and localize, recursively. Having that, we localize our content.
- Now there is a chance that some of args have missing internalization. In that case, we insert arg name as placeholder and mark it as broken. Then we repeat whole procedure on fallback language if we have it.
- Otherwise, return result from (1).
pub fn get_content_fallback(&self, content: &Content) -> String
sourcepub fn get_variation_ctx<'a>(
&'a self,
key: &str,
seed: u16,
args: &'a FluentArgs<'_>,
) -> Cow<'_, str>
pub fn get_variation_ctx<'a>( &'a self, key: &str, seed: u16, args: &'a FluentArgs<'_>, ) -> Cow<'_, str>
NOTE: Exists for legacy reasons, avoid.
Get a localized text from the variation of given key with given arguments
First lookup is done in the active language, second in the fallback (if present). If the key is not present in the localization object then the key itself is returned.
sourcepub fn try_attr(&self, key: &str, attr: &str) -> Option<Cow<'_, str>>
pub fn try_attr(&self, key: &str, attr: &str) -> Option<Cow<'_, str>>
Get a localized text from the given key by given attribute
First lookup is done in the active language, second in the fallback (if present).
sourcepub fn get_attr(&self, key: &str, attr: &str) -> Cow<'_, str>
pub fn get_attr(&self, key: &str, attr: &str) -> Cow<'_, str>
Get a localized text from the given key by given attribute
First lookup is done in the active language, second in the fallback (if present). If the key is not present in the localization object then the key itself is returned.
sourcepub fn try_attr_ctx(
&self,
key: &str,
attr: &str,
args: &FluentArgs<'_>,
) -> Option<Cow<'static, str>>
pub fn try_attr_ctx( &self, key: &str, attr: &str, args: &FluentArgs<'_>, ) -> Option<Cow<'static, str>>
Get a localized text from the given key by given attribute and arguments
First lookup is done in the active language, second in the fallback (if present).
sourcepub fn get_attr_ctx(
&self,
key: &str,
attr: &str,
args: &FluentArgs<'_>,
) -> Cow<'static, str>
pub fn get_attr_ctx( &self, key: &str, attr: &str, args: &FluentArgs<'_>, ) -> Cow<'static, str>
Get a localized text from the given key by given attribute and arguments
First lookup is done in the active language, second in the fallback (if present). If the key is not present in the localization object then the key itself is returned.
pub fn fonts(&self) -> &Fonts
pub fn metadata(&self) -> &LanguageMetadata
Auto Trait Implementations§
impl Freeze for LocalizationGuard
impl !RefUnwindSafe for LocalizationGuard
impl !Send for LocalizationGuard
impl Sync for LocalizationGuard
impl Unpin for LocalizationGuard
impl !UnwindSafe for LocalizationGuard
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more