feat: 喵语翻译插件增加国际化支持

release/desktop
moonrailgun 3 years ago
parent 2a2b33578a
commit 8d18e70233

@ -7,7 +7,8 @@ import {
ChatInputActionContextProps, ChatInputActionContextProps,
} from '@capital/common'; } from '@capital/common';
import { Button, TextArea } from '@capital/component'; import { Button, TextArea } from '@capital/component';
import { encode } from './trans'; import { encode } from './miaotrans';
import { Translate } from './translate';
interface SendMiaoModalProps { interface SendMiaoModalProps {
actions: ChatInputActionContextProps; actions: ChatInputActionContextProps;
@ -25,9 +26,9 @@ export const SendMiaoModal: React.FC<SendMiaoModalProps> = React.memo(
}, [text, modalContext, props.actions]); }, [text, modalContext, props.actions]);
return ( return (
<ModalWrapper title="喵言喵语"> <ModalWrapper title={Translate.title}>
<TextArea <TextArea
placeholder="输入人话" placeholder={Translate.inputHuman}
value={text} value={text}
onChange={(e) => setText(e.target.value)} onChange={(e) => setText(e.target.value)}
/> />
@ -38,7 +39,7 @@ export const SendMiaoModal: React.FC<SendMiaoModalProps> = React.memo(
block={true} block={true}
onClick={handleSendMiao} onClick={handleSendMiao}
> >
{Translate.send}
</Button> </Button>
</ModalWrapper> </ModalWrapper>
); );

@ -1,4 +1,4 @@
import { decode, encode, isMiao } from './trans'; import { decode, encode, isMiao } from './miaotrans';
import { import {
regMessageInterpreter, regMessageInterpreter,
regChatInputAction, regChatInputAction,
@ -6,6 +6,7 @@ import {
} from '@capital/common'; } from '@capital/common';
import { createElement } from 'react'; import { createElement } from 'react';
import { SendMiaoModal } from './SendMiaoModal'; import { SendMiaoModal } from './SendMiaoModal';
import { Translate } from './translate';
const miao = encode('喵语翻译已加载'); const miao = encode('喵语翻译已加载');
const human = decode(miao); const human = decode(miao);
@ -13,7 +14,7 @@ const human = decode(miao);
console.log(`${miao}\n${human}`); console.log(`${miao}\n${human}`);
regMessageInterpreter({ regMessageInterpreter({
name: '喵语翻译', name: Translate.miaoTrans,
explainMessage(message: string) { explainMessage(message: string) {
// 喵语 -> 人话 // 喵语 -> 人话
if (!isMiao(message)) { if (!isMiao(message)) {
@ -25,7 +26,7 @@ regMessageInterpreter({
}); });
regChatInputAction({ regChatInputAction({
label: '喵言喵语', label: Translate.title,
onClick: (actions) => { onClick: (actions) => {
openModal(createElement(SendMiaoModal, { actions })); openModal(createElement(SendMiaoModal, { actions }));
}, },

@ -1,7 +1,10 @@
import Miao from 'miao-lang'; import Miao from 'miao-lang';
import { Translate } from './translate';
export function encode(human: string): string { export function encode(human: string): string {
return Miao.encode(human); return Miao.encode(human, {
calls: Translate.calls,
});
} }
export function decode(miao: string): string { export function decode(miao: string): string {

@ -0,0 +1,9 @@
import { localTrans } from '@capital/common';
export const Translate = {
miaoTrans: localTrans({ 'zh-CN': '喵语翻译', 'en-US': 'Meow Translate' }),
title: localTrans({ 'zh-CN': '喵言喵语', 'en-US': 'Meow meow' }),
send: localTrans({ 'zh-CN': '发送喵语', 'en-US': 'Send meow' }),
inputHuman: localTrans({ 'zh-CN': '输入人话', 'en-US': 'Input Human' }),
calls: localTrans({ 'zh-CN': '喵', 'en-US': 'Meow~' }),
};

@ -1,6 +1,5 @@
{ {
"compilerOptions": { "compilerOptions": {
"rootDir": "./src",
"baseUrl": "./src", "baseUrl": "./src",
"esModuleInterop": true, "esModuleInterop": true,
"jsx": "react", "jsx": "react",

Loading…
Cancel
Save