use day_pieces::{IntoText, TextSource};
pub use day_localization::{
Catalog, DateFields, FArg, IntoFArg, IntoNumberFArg, SigM, ValM, add_launch_locales, compare,
compare_in, format_catalog, format_date, format_date_in, format_decimal, format_decimal_in,
format_in, format_percent, format_percent_in, key, locale, matches_search, matches_search_in,
register_catalog, set_launch_locale, set_launch_locales, set_locale, sort_localized,
strip_isolates, t,
};
pub fn install(default: &str, locales: &[(&str, &str)]) {
day_localization::install(default, locales);
day_core::set_layout_direction(day_core::direction_of_locale(
&day_localization::locale().get_untracked(),
));
}
#[derive(Clone)]
pub struct LocalizedText {
key: String,
catalog: Option<&'static Catalog>,
args: Vec<(String, FArg)>,
}
pub fn tr(key: &str) -> LocalizedText {
LocalizedText {
key: key.to_owned(),
catalog: None,
args: Vec::new(),
}
}
pub fn tr_in(catalog: &'static Catalog, key: &str) -> LocalizedText {
register_catalog(catalog);
LocalizedText {
key: key.to_owned(),
catalog: Some(catalog),
args: Vec::new(),
}
}
pub mod res {
pub mod str {
use crate::{LocalizedText, tr};
day_localization::__core_strings!();
}
}
#[macro_export]
macro_rules! locales {
() => {
pub mod res {
include!(concat!(env!("OUT_DIR"), "/day_locales.rs"));
}
};
}
impl LocalizedText {
pub fn arg<M>(mut self, name: &str, value: impl IntoFArg<M>) -> Self {
self.args.push((name.to_owned(), value.into_farg()));
self
}
pub fn format(&self) -> String {
match self.catalog {
Some(catalog) => format_catalog(catalog, &locale().get(), &self.key, &self.args),
None => format_in(&locale().get(), &self.key, &self.args),
}
}
}
impl From<LocalizedText> for String {
fn from(t: LocalizedText) -> String {
t.format()
}
}
pub struct LocalizedMark;
impl IntoText<LocalizedMark> for LocalizedText {
fn into_text(self) -> TextSource {
TextSource::Dyn(std::rc::Rc::new(move || self.format()))
}
}