mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 08:04:52 +01:00
language beginning
This commit is contained in:
@@ -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<IProps, IState> {
|
||||
@@ -19,7 +22,9 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
||||
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<IProps, IState>
|
||||
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<IProps, IState>
|
||||
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<IProps, IState>
|
||||
return (
|
||||
<div id="playButton">
|
||||
<div id="serverControls">
|
||||
<Checkbox id="enableGC" label="Connect via Grasscutter" onChange={this.toggleGrasscutter} checked={this.state.grasscutterEnabled}/>
|
||||
<Checkbox id="enableGC" label={this.state.checkboxLabel} onChange={this.toggleGrasscutter} checked={this.state.grasscutterEnabled}/>
|
||||
</div>
|
||||
<BigButton text="Launch" onClick={this.playGame} id="officialPlay" />
|
||||
<BigButton text={this.state.buttonLabel} onClick={this.playGame} id="officialPlay" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,18 +7,10 @@ interface IProps {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface IState {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export default class BigButton extends React.Component<IProps, IState> {
|
||||
export default class BigButton extends React.Component<IProps, never> {
|
||||
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<IProps, IState> {
|
||||
render() {
|
||||
return (
|
||||
<div className="BigButton" onClick={this.handleClick} id={this.props.id}>
|
||||
<div className="BigButtonText">{this.state.text}</div>
|
||||
<div className="BigButtonText">{this.props.text}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@ export default class Tr extends React.Component<IProps, IState> {
|
||||
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<IProps, IState> {
|
||||
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<string, string> = 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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user