优化
This commit is contained in:
11
client/web/plugins/com.msgbyte.miaolang/README.md
Normal file
11
client/web/plugins/com.msgbyte.miaolang/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
## 喵语翻译
|
||||
|
||||
允许用户将自然语言转换为加密后的喵语
|
||||
|
||||
在任意聊天款的右侧添加喵语翻译
|
||||
|
||||

|
||||
|
||||
在此输入的任意内容都会被转换为加密后的喵语言,只有安装了相同插件的用户才能翻译
|
||||
|
||||

|
||||
BIN
client/web/plugins/com.msgbyte.miaolang/docs/output.png
Normal file
BIN
client/web/plugins/com.msgbyte.miaolang/docs/output.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.6 KiB |
BIN
client/web/plugins/com.msgbyte.miaolang/docs/send.png
Normal file
BIN
client/web/plugins/com.msgbyte.miaolang/docs/send.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.5 KiB |
12
client/web/plugins/com.msgbyte.miaolang/manifest.json
Normal file
12
client/web/plugins/com.msgbyte.miaolang/manifest.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"label": "Miaolang",
|
||||
"label.zh-CN": "喵语言",
|
||||
"name": "com.msgbyte.miaolang",
|
||||
"url": "/plugins/com.msgbyte.miaolang/index.js",
|
||||
"version": "0.0.0",
|
||||
"author": "msgbyte",
|
||||
"description": "It is allowed to send meow, and the two parties encrypt the conversation after installing the plugin. People who have not installed the plugin will see 'meow'",
|
||||
"description.zh-CN": "允许发送喵语,安装插件后的双方加密对话,未安装插件的人看到的是 '喵'",
|
||||
"documentUrl": "/plugins/com.msgbyte.miaolang/README.md",
|
||||
"requireRestart": false
|
||||
}
|
||||
9
client/web/plugins/com.msgbyte.miaolang/package.json
Normal file
9
client/web/plugins/com.msgbyte.miaolang/package.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "@plugins/com.msgbyte.miaolang",
|
||||
"main": "src/index.ts",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"miao-lang": "^1.0.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import React from 'react';
|
||||
import { useCallback } from 'react';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
ModalWrapper,
|
||||
useModalContext,
|
||||
ChatInputActionContextProps,
|
||||
} from '@capital/common';
|
||||
import { Button, TextArea } from '@capital/component';
|
||||
import { encode } from './miaotrans';
|
||||
import { Translate } from './translate';
|
||||
|
||||
interface SendMiaoModalProps {
|
||||
actions: ChatInputActionContextProps;
|
||||
}
|
||||
export const SendMiaoModal: React.FC<SendMiaoModalProps> = React.memo(
|
||||
(props) => {
|
||||
const [text, setText] = useState('');
|
||||
const modalContext = useModalContext();
|
||||
|
||||
const handleSendMiao = useCallback(() => {
|
||||
const miao = encode(text);
|
||||
|
||||
props.actions.sendMsg(miao);
|
||||
modalContext?.closeModal();
|
||||
}, [text, modalContext, props.actions]);
|
||||
|
||||
return (
|
||||
<ModalWrapper title={Translate.title}>
|
||||
<TextArea
|
||||
placeholder={Translate.inputHuman}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
/>
|
||||
|
||||
<Button
|
||||
style={{ marginTop: 8 }}
|
||||
type="primary"
|
||||
block={true}
|
||||
onClick={handleSendMiao}
|
||||
>
|
||||
{Translate.send}
|
||||
</Button>
|
||||
</ModalWrapper>
|
||||
);
|
||||
}
|
||||
);
|
||||
SendMiaoModal.displayName = 'SendMiaoModal';
|
||||
19
client/web/plugins/com.msgbyte.miaolang/src/index.ts
Normal file
19
client/web/plugins/com.msgbyte.miaolang/src/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { regChatInputAction, openModal, Loadable } from '@capital/common';
|
||||
import { createElement } from 'react';
|
||||
import { Translate } from './translate';
|
||||
|
||||
const SendMiaoModal = Loadable(() =>
|
||||
import('./SendMiaoModal').then((module) => ({
|
||||
default: module.SendMiaoModal,
|
||||
}))
|
||||
);
|
||||
|
||||
// Just for reduce entry file size
|
||||
import('./reg');
|
||||
|
||||
regChatInputAction({
|
||||
label: Translate.title,
|
||||
onClick: (actions) => {
|
||||
openModal(createElement(SendMiaoModal, { actions }));
|
||||
},
|
||||
});
|
||||
18
client/web/plugins/com.msgbyte.miaolang/src/miaotrans.ts
Normal file
18
client/web/plugins/com.msgbyte.miaolang/src/miaotrans.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import Miao from 'miao-lang';
|
||||
import { Translate } from './translate';
|
||||
import { getLanguage } from '@capital/common';
|
||||
|
||||
export function encode(human: string): string {
|
||||
return Miao.encode(human, {
|
||||
calls: Translate.calls,
|
||||
halfwidthSymbol: getLanguage() !== 'zh-CN',
|
||||
});
|
||||
}
|
||||
|
||||
export function decode(miao: string): string {
|
||||
return Miao.decode(miao);
|
||||
}
|
||||
|
||||
export function isMiao(input: string): boolean {
|
||||
return Miao.isMiao(input);
|
||||
}
|
||||
20
client/web/plugins/com.msgbyte.miaolang/src/reg.ts
Normal file
20
client/web/plugins/com.msgbyte.miaolang/src/reg.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { decode, encode, isMiao } from './miaotrans';
|
||||
import { regMessageInterpreter } from '@capital/common';
|
||||
import { Translate } from './translate';
|
||||
|
||||
const miao = encode('喵语翻译已加载');
|
||||
const human = decode(miao);
|
||||
|
||||
console.log(`${miao}\n${human}`);
|
||||
|
||||
regMessageInterpreter({
|
||||
name: Translate.miaoTrans,
|
||||
explainMessage(message: string) {
|
||||
// 喵语 -> 人话
|
||||
if (!isMiao(message)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return decode(message);
|
||||
},
|
||||
});
|
||||
9
client/web/plugins/com.msgbyte.miaolang/src/translate.ts
Normal file
9
client/web/plugins/com.msgbyte.miaolang/src/translate.ts
Normal file
@@ -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~' }),
|
||||
};
|
||||
9
client/web/plugins/com.msgbyte.miaolang/tsconfig.json
Normal file
9
client/web/plugins/com.msgbyte.miaolang/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react",
|
||||
"paths": {
|
||||
"@capital/*": ["../../src/plugin/*"],
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user