feat: internationalization #43
19
src/internationalization/cs_cz.json
Normal file
19
src/internationalization/cs_cz.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"id": "cs-CZ",
|
||||
"texts": {
|
||||
"none": "žádný",
|
||||
"long_term": "dlouhodobé",
|
||||
"yesterday": "včera",
|
||||
"today": "dnes",
|
||||
"tomorrow": "zítra",
|
||||
"overdue": "zpožděné",
|
||||
"formats": {
|
||||
"date_format": "%-d. %B",
|
||||
"date_year_format": "%-d. %B %Y",
|
||||
"date_weekday_format": "%A %-d. %B",
|
||||
"date_weekday_year_format": "%A %-d. %B %Y",
|
||||
"weekday_lowercase_first": "true",
|
||||
"time_format": "%-H:%M"
|
||||
}
|
||||
}
|
||||
}
|
19
src/internationalization/en_us.json
Normal file
19
src/internationalization/en_us.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"id": "en-US",
|
||||
"texts": {
|
||||
"none": "none",
|
||||
"long_term": "long-term",
|
||||
"yesterday": "yesterday",
|
||||
"today": "today",
|
||||
"tomorrow": "tomorrow",
|
||||
"overdue": "overdue",
|
||||
"formats": {
|
||||
"date_format": "%B %-d",
|
||||
"date_year_format": "%B %-d, %Y",
|
||||
"date_weekday_format": "%A, %B %-d",
|
||||
"date_weekday_year_format": "%A, %B %-d, %Y",
|
||||
"weekday_lowercase_first": "false",
|
||||
"time_format": "%-I:%M %P"
|
||||
}
|
||||
}
|
||||
}
|
34
src/internationalization/mod.rs
Normal file
34
src/internationalization/mod.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use std::ops::Deref;
|
||||
use std::str::FromStr;
|
||||
use chrono::Locale;
|
||||
use dioxus_sdk::i18n::Language;
|
||||
use unic_langid_impl::LanguageIdentifier;
|
||||
|
||||
const EN_US: &str = include_str!("en_us.json");
|
||||
const CS_CZ: &str = include_str!("cs_cz.json");
|
||||
|
||||
pub(crate) fn get_languages() -> Vec<Language> {
|
||||
Vec::from([EN_US, CS_CZ]).into_iter().map(|texts| Language::from_str(texts).unwrap()).collect()
|
||||
}
|
||||
|
||||
pub(crate) struct LocaleFromLanguageIdentifier<'a>(&'a LanguageIdentifier);
|
||||
|
||||
impl<'a> Deref for LocaleFromLanguageIdentifier<'a> {
|
||||
type Target = LanguageIdentifier;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<LocaleFromLanguageIdentifier<'a>> for Locale {
|
||||
fn from(language_identifier: LocaleFromLanguageIdentifier) -> Self {
|
||||
language_identifier.to_string().replace("-", "_").parse().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a LanguageIdentifier> for LocaleFromLanguageIdentifier<'a> {
|
||||
fn from(language_identifier: &'a LanguageIdentifier) -> Self {
|
||||
LocaleFromLanguageIdentifier(language_identifier)
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ mod schema;
|
||||
mod server;
|
||||
mod query;
|
||||
mod utils;
|
||||
mod internationalization;
|
||||
|
||||
use components::app::App;
|
||||
use dioxus::prelude::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user