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 languageslist: LangList
- List of translationsdefault: 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
impl Lang
Sourcepub async fn new(root: Arc<String>, default_lang: &str, db: &mut DB) -> Lang
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.