pub struct Lang {
pub langs: Vec<LangItem>,
pub list: BTreeMap<i64, BTreeMap<i64, BTreeMap<i64, Arc<BTreeMap<i64, String>>>>>,
pub default: usize,
}Expand description
Descrives all languages
Values
langs: Vec<LangItem>- List of languageslist: LangList- List of translationsdefault: usize- Default language
Fields§
§langs: Vec<LangItem>List of languages
list: BTreeMap<i64, BTreeMap<i64, BTreeMap<i64, Arc<BTreeMap<i64, String>>>>>List of translations
default: usizeDefault language
Implementations§
source§impl Lang
impl Lang
sourcepub fn new(root: &str, default_lang: &str, langs: Vec<LangItem>) -> Lang
pub fn new(root: &str, default_lang: &str, langs: Vec<LangItem>) -> 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.