Struct next_rs::YewI18n

source ·
pub struct YewI18n {
    pub config: YewI18nConfig,
    /* private fields */
}
Expand description

The YewI18n struct representing the state and methods for internationalization.

Fields§

§config: YewI18nConfig

Configuration for YewI18n, specifying supported languages and translations.

Implementations§

source§

impl YewI18n

source

pub fn new( config: YewI18nConfig, translations: HashMap<String, Value> ) -> Result<YewI18n, String>

Creates a new instance of YewI18n.

§Arguments
  • config - Configuration for YewI18n.
  • translations - Translations for different languages.
§Returns

A Result containing the initialized YewI18n instance or an error message.

§Examples
use yew_i18n::{YewI18n, YewI18nConfig};
use std::collections::HashMap;

let supported_languages = vec!["en", "fr"];
let translations = HashMap::new();

let result = YewI18n::new(YewI18nConfig { supported_languages, translations: translations.clone()}, translations);
assert!(result.is_ok());
source

pub fn set_translation_language(&mut self, language: &str) -> Result<(), String>

Sets the current language for translations.

§Arguments
  • language - The language code to set.
§Returns

A Result indicating success or an error message if the language is not supported.

§Examples
use yew_i18n::{YewI18n, YewI18nConfig};
use std::collections::HashMap;

let supported_languages = vec!["en", "fr"];
let translations = HashMap::new();

let mut i18n = YewI18n::new(YewI18nConfig { supported_languages, translations: translations.clone()}, translations).unwrap();
assert!(i18n.set_translation_language("fr").is_ok());
source

pub fn t(&self, key: &str) -> String

Retrieves a translated string for a given key.

§Arguments
  • key - The translation key.
§Returns

The translated string or an error message if the key is not found.

§Examples
use yew_i18n::{YewI18n, YewI18nConfig};
use std::collections::HashMap;
use serde_json::json;

let supported_languages = vec!["en", "fr"];
let mut translations = HashMap::new();
translations.insert("en".to_string(), json!({ "greeting": "Hello" }));
translations.insert("fr".to_string(), json!({ "greeting": "Bonjour" }));

let i18n = YewI18n::new(YewI18nConfig { supported_languages, translations: translations.clone()}, translations).unwrap();
assert_eq!(i18n.t("greeting"), "Hello");

Trait Implementations§

source§

impl Clone for YewI18n

source§

fn clone(&self) -> YewI18n

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl PartialEq for YewI18n

source§

fn eq(&self, other: &YewI18n) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for YewI18n

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> IntoPropValue<Option<T>> for T

source§

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
source§

impl<T> IntoPropValue<T> for T

source§

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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
source§

impl<T> HasAllProps<(), T> for T