🚧 Simplifies translated text handling
This commit is contained in:
parent
c2d0c2a80d
commit
e25cc16859
3 changed files with 13 additions and 19 deletions
|
|
@ -19,7 +19,7 @@ pub trait ModuleTrait: HasHandle + ModuleBase + Send + Sync {
|
|||
}
|
||||
|
||||
fn description(&self) -> L10n {
|
||||
L10n::default()
|
||||
L10n::none()
|
||||
}
|
||||
|
||||
fn theme(&self) -> Option<ThemeRef> {
|
||||
|
|
|
|||
|
|
@ -1,36 +1,31 @@
|
|||
use crate::fn_builder;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::html::Markup;
|
||||
use crate::locale::{L10n, LanguageIdentifier};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct OptionTranslated(Option<L10n>);
|
||||
|
||||
pub struct OptionTranslated(L10n);
|
||||
|
||||
impl OptionTranslated {
|
||||
pub fn new(value: L10n) -> Self {
|
||||
OptionTranslated::default().with_value(value)
|
||||
OptionTranslated(value)
|
||||
}
|
||||
|
||||
// OptionTranslated BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_value(&mut self, value: L10n) -> &mut Self {
|
||||
self.0 = Some(value);
|
||||
self.0 = value;
|
||||
self
|
||||
}
|
||||
|
||||
// OptionTranslated GETTERS.
|
||||
|
||||
pub fn using(&self, langid: &LanguageIdentifier) -> Option<String> {
|
||||
if let Some(value) = &self.0 {
|
||||
return value.using(langid);
|
||||
}
|
||||
None
|
||||
self.0.using(langid)
|
||||
}
|
||||
|
||||
pub fn escaped(&self, langid: &LanguageIdentifier) -> Markup {
|
||||
match &self.0 {
|
||||
Some(value) => value.escaped(langid),
|
||||
_ => html! {},
|
||||
}
|
||||
self.0.escaped(langid)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,14 +185,13 @@ pub struct L10n {
|
|||
}
|
||||
|
||||
impl L10n {
|
||||
pub fn none() -> Self {
|
||||
L10n::default()
|
||||
}
|
||||
|
||||
pub fn n(text: impl Into<String>) -> Self {
|
||||
let text = text.into();
|
||||
L10n {
|
||||
op: if text.trim().is_empty() {
|
||||
L10nOp::None
|
||||
} else {
|
||||
L10nOp::Text(text)
|
||||
},
|
||||
op: L10nOp::Text(text.into()),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue