tooltip raw text, inline translation fallback support
This commit is contained in:
@@ -109,7 +109,11 @@ impl I18n {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn translate(&mut self, translation_key: &str) -> Rc<str> {
|
||||
pub fn translate(&mut self, translation_key_full: &str) -> Rc<str> {
|
||||
let translation_key = translation_key_full
|
||||
.split_once(';')
|
||||
.map_or(translation_key_full, |(a, _)| a);
|
||||
|
||||
if let Some(translated) = find_translation(translation_key, &self.json_root_translated) {
|
||||
return Rc::from(translated);
|
||||
}
|
||||
@@ -119,6 +123,11 @@ impl I18n {
|
||||
return Rc::from(translated_fallback);
|
||||
}
|
||||
|
||||
// not even found in fallback, check if the translation contains ";" (to be used as "MY_TRANSLATION_KEY;A fallback text")
|
||||
if let Some((idx, _)) = translation_key_full.match_indices(';').next() {
|
||||
return Rc::from(&translation_key_full[idx + 1..]);
|
||||
}
|
||||
|
||||
log::error!("missing translation for key \"{translation_key}\"");
|
||||
Rc::from(translation_key) // show translation key as a fallback
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user