mirror of
https://codeberg.org/simonrepp/hyper8.git
synced 2026-08-14 13:45:27 +02:00
Introduce translations, translate and style copy link widget
This commit is contained in:
@@ -17,6 +17,7 @@ mod playlist;
|
||||
mod render;
|
||||
mod scripts;
|
||||
mod styles;
|
||||
pub mod translations;
|
||||
mod video;
|
||||
mod widgets;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -79,11 +79,11 @@ pub fn layout(
|
||||
</body>
|
||||
"##);
|
||||
|
||||
let lang = site.language.code();
|
||||
let lang_code = &site.language.code;
|
||||
|
||||
formatdoc!(r#"
|
||||
<!doctype html>
|
||||
<html lang="{lang}">
|
||||
<html lang="{lang_code}">
|
||||
{head}
|
||||
{body}
|
||||
</html>
|
||||
|
||||
+6
-2
@@ -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}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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#"
|
||||
<div>
|
||||
<button {data_url} id="copy-link">Copy link</button>
|
||||
<button {data_url} id="copy-link">{t_copy_link}</button>
|
||||
</div>
|
||||
"#)
|
||||
}
|
||||
@@ -144,10 +144,9 @@ fn edit_page(
|
||||
r#"<span class="feedback">Not Saved</span>"#
|
||||
)
|
||||
} 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)
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
+27
-18
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user