diff --git a/src/build.rs b/src/build.rs index d90bb83..f675ab3 100644 --- a/src/build.rs +++ b/src/build.rs @@ -17,6 +17,7 @@ mod playlist; mod render; mod scripts; mod styles; +pub mod translations; mod video; mod widgets; diff --git a/src/build/assets/styles.css b/src/build/assets/styles.css index 41e41d3..4badf69 100644 --- a/src/build/assets/styles.css +++ b/src/build/assets/styles.css @@ -13,6 +13,10 @@ body { font-family: sans-serif; margin: 0; } +button { + color: var(--c-fg-2); + font-size: 1rem; +} h1 { font-size: 1.5rem; } h2 { font-size: 1.17rem; } video { width: 100%; } @@ -49,8 +53,22 @@ video { width: 100%; } left: 50%; transform: translateX(-50%); } -#copy-link.confirmed { border-color: green; } -#copy-link.failed { border-color: red; } +:root { + --copied: 'Copied'; + --failed: 'Failed'; +} +#copy-link { + background: none; + border: none; + color: var(--c-fg-1); + cursor: pointer; +} +#copy-link::after { + color: var(--c-fg-2); + padding-left: .5rem; +} +#copy-link.confirmed::after { content: var(--copied); } +#copy-link.failed::after { content: var(--failed); } .current { background-color: var(--c-bg-3); } diff --git a/src/build/render.rs b/src/build/render.rs index 8ec3949..7c58220 100644 --- a/src/build/render.rs +++ b/src/build/render.rs @@ -79,11 +79,11 @@ pub fn layout( "##); - let lang = site.language.code(); + let lang_code = &site.language.code; formatdoc!(r#" - + {head} {body} diff --git a/src/build/styles.rs b/src/build/styles.rs index 640a15b..e7d65cd 100644 --- a/src/build/styles.rs +++ b/src/build/styles.rs @@ -7,8 +7,6 @@ use crate::{Context, Site, ThemeKind}; pub fn generate(context: &Context, site: &Site) { let static_css = include_str!("assets/styles.css"); - let poster_aspect = site.poster_aspect.numeric(); - let theme_vars = match &site.theme.kind { ThemeKind::Adaptive { dark, light } => { let static_adaptive_theme_css = include_str!("assets/adaptive_theme.css"); @@ -37,9 +35,15 @@ pub fn generate(context: &Context, site: &Site) { } }; + let poster_aspect = site.poster_aspect.numeric(); + let t_copied = &site.language.translations.copied; + let t_failed = &site.language.translations.failed; + let css = formatdoc!(r#" :root {{ --poster-aspect: {poster_aspect}; + --t-copied: '{t_copied}'; + --t-failed: '{t_failed}'; }} {theme_vars} {static_css} diff --git a/src/build/translations.rs b/src/build/translations.rs new file mode 100644 index 0000000..fa1ab1a --- /dev/null +++ b/src/build/translations.rs @@ -0,0 +1,24 @@ +#[derive(Clone, Debug)] +pub struct Translations { + pub copied: String, + pub copy_link: String, + pub failed: String +} + +impl Translations { + pub fn de() -> Translations { + Translations { + copied: String::from("Kopiert"), + copy_link: String::from("Link kopieren"), + failed: String::from("Fehlgeschlagen") + } + } + + pub fn en() -> Translations { + Translations { + copied: String::from("Copied"), + copy_link: String::from("Copy link"), + failed: String::from("Failed") + } + } +} diff --git a/src/build/widgets.rs b/src/build/widgets.rs index 1520edf..f8dbbc1 100644 --- a/src/build/widgets.rs +++ b/src/build/widgets.rs @@ -9,9 +9,11 @@ pub fn copy_link(site: &Site, path: &str) -> String { None => String::new() }; + let t_copy_link = &site.language.translations.copy_link; + format!(r#"
- +
"#) } \ No newline at end of file diff --git a/src/editor/endpoints/site.rs b/src/editor/endpoints/site.rs index 0dc8a67..a92d366 100644 --- a/src/editor/endpoints/site.rs +++ b/src/editor/endpoints/site.rs @@ -144,10 +144,9 @@ fn edit_page( r#"Not Saved"# ) } else { - let language = match &site.language { - Language::Default => "", - Language::Supported(code) => code, - Language::Unsupported(code) => code + let language = match site.language.default { + true => "", + false => &site.language.code }; let poster_aspect = match &site.poster_aspect { @@ -288,7 +287,7 @@ pub async fn update( Either::Right(http_response) } else { let language = if language_trimmed.is_empty() { - Language::Default + Language::default() } else { Language::from_code(language_trimmed) }; diff --git a/src/main.rs b/src/main.rs index aa48ef7..d9a3d91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ mod workers; use args::Args; use banner::Banner; +use build::translations::Translations; use browser_support::BrowserSupport; use cache::{Cache, CacheItem, FileMeta, PosterAssetsCached, VideoMetaCached}; use collection::Collection; diff --git a/src/site.rs b/src/site.rs index 107ecb1..b2292d7 100644 --- a/src/site.rs +++ b/src/site.rs @@ -12,6 +12,7 @@ use crate::{ HyperDir, Playlist, Theme, + Translations, Video }; @@ -25,10 +26,10 @@ pub enum AspectRatio { } #[derive(Clone, Debug)] -pub enum Language { - Default, - Supported(String), - Unsupported(String) +pub struct Language { + pub code: String, + pub default: bool, + pub translations: Translations } #[derive(Clone, Debug)] @@ -86,19 +87,29 @@ impl AspectRatio { } impl Language { - pub fn code(&self) -> &str { - match self { - Language::Default => "en", - Language::Supported(code) => code, - Language::Unsupported(code) => code + pub fn default() -> Language { + Language { + code: String::from("en"), + default: true, + translations: Translations::en() } } pub fn from_code(code: &str) -> Language { - match code { - "de" => Language::Supported(code.to_string()), - "en" => Language::Supported(code.to_string()), - _ => Language::Unsupported(code.to_string()) + let translations = match code { + "de" => Translations::de(), + "en" => Translations::en(), + _ => Translations::en() + }; + + Language::manual(code.to_string(), translations) + } + + pub fn manual(code: String, translations: Translations) -> Language { + Language { + code, + default: false, + translations } } } @@ -257,7 +268,7 @@ impl Site { base_url: None, content: SiteContent::Empty, errors: Vec::new(), - language: Language::Default, + language: Language::default(), poster_aspect: AspectRatio::Default, theme: Theme::default() } @@ -323,10 +334,8 @@ impl Site { eno.push_str(&format!("base_url: {}\n", base_url)); } - if let Language::Supported(code) = &self.language { - eno.push_str(&format!("language: {}\n", code)); - } else if let Language::Unsupported(code) = &self.language { - eno.push_str(&format!("language: {}\n", code)); + if !self.language.default { + eno.push_str(&format!("language: {}\n", self.language.code)); } if let AspectRatio::Custom { representation, .. } = &self.poster_aspect {