feat(client): add RU/EN localization and native capture preview
This commit is contained in:
parent
8e5ab56611
commit
8460fb28fd
43 changed files with 4103 additions and 275 deletions
|
|
@ -49,10 +49,12 @@ impl AppearancePreferences {
|
|||
|
||||
pub fn resolve(&self) -> Result<ThemeSpec, String> {
|
||||
if !["light", "dark", "black", "custom"].contains(&self.mode.as_str()) {
|
||||
return Err("Неизвестная тема.".into());
|
||||
return Err(crate::ui::i18n::text("Unknown theme."));
|
||||
}
|
||||
if !self.font_size.is_finite() || !(12.0..=22.0).contains(&self.font_size) {
|
||||
return Err("Размер текста должен быть от 12px до 22px.".into());
|
||||
return Err(crate::ui::i18n::text(
|
||||
"Text size must be between 12px and 22px.",
|
||||
));
|
||||
}
|
||||
let mut theme = if self.mode == "custom" {
|
||||
parse_css(&self.custom_css)?
|
||||
|
|
@ -88,19 +90,28 @@ fn check_css_path(path: &Path) -> Result<(), String> {
|
|||
.and_then(|s| s.to_str())
|
||||
.is_none_or(|ext| !ext.eq_ignore_ascii_case("css"))
|
||||
{
|
||||
return Err("Укажи путь к файлу с расширением .css.".into());
|
||||
return Err(crate::ui::i18n::text("Enter a file path ending in .css."));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn import_css(path: &Path) -> Result<String, String> {
|
||||
check_css_path(path)?;
|
||||
let file =
|
||||
std::fs::File::open(path).map_err(|error| format!("Не удалось открыть тему: {error}"))?;
|
||||
let file = std::fs::File::open(path).map_err(|error| {
|
||||
crate::ui::i18n::format(
|
||||
"Could not open theme: {error}",
|
||||
&[("error", error.to_string())],
|
||||
)
|
||||
})?;
|
||||
let mut css = String::new();
|
||||
file.take(MAX_CSS_BYTES as u64 + 1)
|
||||
.read_to_string(&mut css)
|
||||
.map_err(|error| format!("Не удалось прочитать CSS: {error}"))?;
|
||||
.map_err(|error| {
|
||||
crate::ui::i18n::format(
|
||||
"Could not read CSS: {error}",
|
||||
&[("error", error.to_string())],
|
||||
)
|
||||
})?;
|
||||
parse_css(&css)?;
|
||||
Ok(css)
|
||||
}
|
||||
|
|
@ -109,11 +120,19 @@ pub fn export_css(path: &Path, theme: &ThemeSpec) -> Result<(), String> {
|
|||
check_css_path(path)?;
|
||||
// The path is explicitly provided by the local export action. No network I/O.
|
||||
if let Some(parent) = path.parent().filter(|p| !p.as_os_str().is_empty()) {
|
||||
std::fs::create_dir_all(parent)
|
||||
.map_err(|e| format!("Не удалось создать папку темы: {e}"))?;
|
||||
std::fs::create_dir_all(parent).map_err(|e| {
|
||||
crate::ui::i18n::format(
|
||||
"Could not create theme directory: {e}",
|
||||
&[("e", e.to_string())],
|
||||
)
|
||||
})?;
|
||||
}
|
||||
std::fs::write(path, theme.to_css())
|
||||
.map_err(|error| format!("Не удалось сохранить CSS: {error}"))
|
||||
std::fs::write(path, theme.to_css()).map_err(|error| {
|
||||
crate::ui::i18n::format(
|
||||
"Could not save CSS: {error}",
|
||||
&[("error", error.to_string())],
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue