Struct Lang

Source
pub struct Lang {
    pub langs: Arc<Vec<Arc<LangItem>>>,
    pub list: Arc<BTreeMap<i64, BTreeMap<i64, BTreeMap<i64, Arc<BTreeMap<i64, String>>>>>>,
    pub default: usize,
    /* private fields */
}
Expand description

Descrives all languages

§Values

  • langs: Vec<LangItem> - List of languages
  • list: LangList - List of translations
  • default: usize - Default language

Fields§

§langs: Arc<Vec<Arc<LangItem>>>

List of languages

§list: Arc<BTreeMap<i64, BTreeMap<i64, BTreeMap<i64, Arc<BTreeMap<i64, String>>>>>>

List of translations

§default: usize

Default language

Implementations§

Source§

impl Lang

Source

pub async fn new(root: Arc<String>, default_lang: &str, db: &mut DB) -> Lang

Reads ./app/ and recognizes translations

§Description

In the root directory of the project (Init::root_path) the app directory is searched.

Translation files are logically located in this directory.
Each file must be named LangItem::lang and have the extension .lang

§Example:
  • English: ./app/module_name/class_name/en.lang
  • Ukrainian: ./app/module_name/class_name/uk.lang

module_name - Name of the module
class_name - Class name

For all controllers in the same class - one translation file in one language is used.

Each translation file is divided into lines.
Each line consists of a key and a translation.

§Example:

en.lang
about=About
articles=Articles
article=Article
contact=Contact
terms=Terms Conditions
policy=Privacy Policy

§Use in the controller:

To get a translation, it is enough to set the this.lang("contact") function, which will return the corresponding translation.
If no translation is found, the key will be returned.

Trait Implementations§

Source§

impl Debug for Lang

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Lang

§

impl RefUnwindSafe for Lang

§

impl Send for Lang

§

impl Sync for Lang

§

impl Unpin for Lang

§

impl UnwindSafe for Lang

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> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

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