From 8ba3e7022d86b11f47d4853919a6f78b87151953 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Wed, 11 May 2022 23:48:05 -0700 Subject: [PATCH] language beginning --- src/ui/components/ServerLaunchSection.tsx | 21 +++++++++++++++------ src/ui/components/common/BigButton.tsx | 12 ++---------- src/utils/language.ts | 8 ++++---- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index 9760ed0..9dcb682 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -2,6 +2,7 @@ import React from 'react' import Checkbox from './common/Checkbox' import BigButton from './common/BigButton' import { getConfig, saveConfig } from '../../utils/configuration' +import Tr, { translate } from '../../utils/language' import { invoke } from '@tauri-apps/api/tauri' import './ServerLaunchSection.css' @@ -11,7 +12,9 @@ interface IProps { } interface IState { - grasscutterEnabled: boolean + grasscutterEnabled: boolean; + buttonLabel: string; + checkboxLabel: string; } export default class ServerLaunchSection extends React.Component { @@ -19,7 +22,9 @@ export default class ServerLaunchSection extends React.Component super(props) this.state = { - grasscutterEnabled: false + grasscutterEnabled: false, + buttonLabel: '', + checkboxLabel: '' } this.toggleGrasscutter = this.toggleGrasscutter.bind(this) @@ -30,8 +35,12 @@ export default class ServerLaunchSection extends React.Component const config = await getConfig() this.setState({ - grasscutterEnabled: config.toggle_grasscutter + grasscutterEnabled: config.toggle_grasscutter, + buttonLabel: await translate('main.launch_button'), + checkboxLabel: await translate('main.gc_enable') }) + + console.log(this.state) } async toggleGrasscutter() { @@ -48,7 +57,7 @@ export default class ServerLaunchSection extends React.Component if (!config.game_path) return // Connect to proxy - await invoke('connect', { port: 8365 }) + if (config.toggle_grasscutter) await invoke('connect', { port: 8365 }) // Launch the program await invoke('run_program', { path: config.game_path }) @@ -58,9 +67,9 @@ export default class ServerLaunchSection extends React.Component return (
- +
- +
) } diff --git a/src/ui/components/common/BigButton.tsx b/src/ui/components/common/BigButton.tsx index 55d3e2b..e05d29f 100644 --- a/src/ui/components/common/BigButton.tsx +++ b/src/ui/components/common/BigButton.tsx @@ -7,18 +7,10 @@ interface IProps { id: string; } -interface IState { - text: string; -} - -export default class BigButton extends React.Component { +export default class BigButton extends React.Component { constructor(props: IProps) { super(props) - this.state = { - text: props.text - } - this.handleClick = this.handleClick.bind(this) } @@ -29,7 +21,7 @@ export default class BigButton extends React.Component { render() { return (
-
{this.state.text}
+
{this.props.text}
) } diff --git a/src/utils/language.ts b/src/utils/language.ts index 840d2bd..e358d80 100644 --- a/src/utils/language.ts +++ b/src/utils/language.ts @@ -30,8 +30,6 @@ export default class Tr extends React.Component { invoke('get_lang', { lang: language }).then((response) => { const translation_obj = JSON.parse(response as string || '{}') - console.log(translation_obj) - // Traversal if (text.includes('.')) { const keys = text.split('.') @@ -65,17 +63,19 @@ export default class Tr extends React.Component { export async function translate(text: string) { const language = await getConfigOption('language') || 'en' const translation_json = JSON.parse(await invoke('get_lang', { lang: language }) || '{}') + + console.log(translation_json) // Traversal if (text.includes('.')) { const keys = text.split('.') - let translation = '' + let translation: string | Record = translation_json for (let i = 0; i < keys.length; i++) { if (!translation) { translation = '' } else { - translation = translation_json[keys[i]] || '' + translation = typeof translation !== 'string' ? translation[keys[i]] : translation as string } }