Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chinese Simplified translation #1352

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub enum LocaleType {
PtBr,
Fr,
De,
#[sqlx(rename = "zh-CN")]
#[serde(rename = "zh-CN")]
ZhCN,
}

#[derive(Debug, Serialize, Deserialize, sqlx::Type, Clone, PartialEq, Eq)]
Expand All @@ -45,8 +48,8 @@ pub(crate) fn read_settings(filepath: &PathBuf) -> Result<Settings, String> {
font_size: 14,
language: LocaleType::En,
color_theme: ThemeType::Dark,
}
})
},
});
};
let updated = update_settings_with_default(filepath, text)?;
from_str::<Settings>(&updated).map_err(|err| err.to_string())
Expand All @@ -62,10 +65,10 @@ pub(crate) fn update_settings_with_default(
original: String,
) -> Result<String, String> {
let Ok(text) = fs::read_to_string(filepath) else {
return Err("Settings file does not exist".to_string())
return Err("Settings file does not exist".to_string());
};
let Ok(value) = serde_json::from_str::<Value>(text.as_str()) else {
return Err("Failed to load json".to_string())
return Err("Failed to load json".to_string());
};
if value["appearance"]["color_theme"] == Value::Null {
let mut update = value.clone();
Expand All @@ -86,6 +89,7 @@ impl fmt::Display for LocaleType {
LocaleType::PtBr => write!(f, "pt-BR"),
LocaleType::Fr => write!(f, "fr"),
LocaleType::De => write!(f, "de"),
LocaleType::ZhCN => write!(f, "zh-CN"),
}
}
}
4 changes: 4 additions & 0 deletions src/components/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const languages = [
{
label: 'German',
value: 'de'
},
{
label: 'Chinese Simplified',
value: 'zh-CN'
}
]

Expand Down
6 changes: 4 additions & 2 deletions src/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import it from '../locales/it/translation.json'
import pt_BR from '../locales/pt-BR/translation.json'
import fr from '../locales/fr/translation.json'
import de from '../locales/de/translation.json'
import zh_CN from '../locales/zh-CN/translation.json'
import { flattenMessages } from './utils/flattenMessage'
import { createContext, useState } from 'react'
import { IntlProvider } from 'react-intl'

export type localeType = 'en' | 'ja' | 'it' | 'pt-BR' | 'fr'
export type localeType = 'en' | 'ja' | 'it' | 'pt-BR' | 'fr' | 'de' | 'zh-CN'

type Props = {
children: React.ReactNode
Expand All @@ -27,7 +28,8 @@ export const IntlProviderWrapper: React.FC<Props> = props => {
{ locale: 'it', messages: flattenMessages(it) },
{ locale: 'pt-BR', messages: flattenMessages(pt_BR) },
{ locale: 'fr', messages: flattenMessages(fr) },
{ locale: 'de', messages: flattenMessages(de) }
{ locale: 'de', messages: flattenMessages(de) },
{ locale: 'zh-CN', messages: flattenMessages(zh_CN) }
]
const [lang, setLang] = useState(langs[0])

Expand Down
Loading