add language switch in settings page

yhy
Dawn_Ocean 2024-03-07 14:07:38 +08:00
parent c63b7fcca8
commit 6cbd6685bc
2 changed files with 46 additions and 2 deletions

View File

@ -1,10 +1,36 @@
import { AtButton } from 'taro-ui'; import { AtButton, AtList, AtListItem } from 'taro-ui';
import { Component, ReactNode } from 'react'; import { Component, ReactNode } from 'react';
import './settings.scss'; import './settings.scss';
import Taro from '@tarojs/taro'; import Taro from '@tarojs/taro';
import { View } from '@tarojs/components'; import { View, Picker } from '@tarojs/components';
import pt, { Lang } from '@/plain-text';
export default class SettingsPage extends Component { export default class SettingsPage extends Component {
showLangDict: Record<string, Lang> = {
: 'zh_CN',
English: 'en_US',
};
reversedShowLangDict: Record<Lang, string> = {
zh_CN: '简体中文',
en_US: 'English',
};
state = {
selector: ['简体中文', 'English'],
selectorChecked: this.reversedShowLangDict[pt.getCurLang()],
};
onSelect = (e: { detail: { value: string | number } }) => {
this.setState({
selectorChecked: this.state.selector[e.detail.value],
});
pt.setLang(this.showLangDict[this.state.selector[e.detail.value]]);
Taro.reLaunch({
url: '/pages/index/index',
});
};
handleQuit() { handleQuit() {
console.log('Quit'); console.log('Quit');
} }
@ -17,6 +43,20 @@ export default class SettingsPage extends Component {
render(): ReactNode { render(): ReactNode {
return ( return (
<View> <View>
<View>
<Picker
mode='selector'
range={this.state.selector}
onChange={this.onSelect}
>
<AtList>
<AtListItem
title='语言 / Language'
extraText={this.state.selectorChecked}
/>
</AtList>
</Picker>
</View>
<AtButton type='secondary' onClick={this.handleAbout.bind(this)}> <AtButton type='secondary' onClick={this.handleAbout.bind(this)}>
EVA Notify EVA Notify
</AtButton> </AtButton>

View File

@ -46,6 +46,10 @@ class PlainText {
} }
return this.textZhCn; return this.textZhCn;
} }
getCurLang(): Lang {
return this.lang;
}
} }
const pt = new PlainText(); const pt = new PlainText();