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

source

pub fn try_fallback_msg(&self, key: &str) -> Option<Cow<'_, str>>

Get a localized text from the given key in the fallback language.

source

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).

source

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.

source

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).

source

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.

source

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).

source

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.

source

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).

source

pub(crate) fn get_content_for_lang( lang: &Language, content: &Content, ) -> Result<String, String>

source

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
  1. Because content we want is localized itself and has arguments, we iterate over them and localize, recursively. Having that, we localize our content.
  2. 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.
  3. Otherwise, return result from (1).
source

pub fn get_content_fallback(&self, content: &Content) -> String

source

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.

source

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).

source

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.

source

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).

source

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.

source

pub fn fonts(&self) -> &Fonts

source

pub fn metadata(&self) -> &LanguageMetadata

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,