From 69e8bd2902dce979a75f09095a756d9ea6da2540 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 22 Feb 2023 15:15:51 +0800 Subject: [PATCH] feat: add i18n support in plugin store --- apps/cli/src/commands/registry/config.ts | 4 --- client/shared/model/plugin.ts | 2 ++ client/web/src/plugin/PluginStore/Item.tsx | 12 ++++--- client/web/src/plugin/builtin.ts | 40 +++++++++++++++------- client/web/src/plugin/utils.ts | 23 ++++++++++++- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/apps/cli/src/commands/registry/config.ts b/apps/cli/src/commands/registry/config.ts index ef9a25a8..88a6dd76 100644 --- a/apps/cli/src/commands/registry/config.ts +++ b/apps/cli/src/commands/registry/config.ts @@ -16,10 +16,6 @@ export const registryConfigCommand: CommandModule = { describe: 'Config FE Plugin List', type: 'boolean', }) - .option('be', { - describe: 'Config BE Plugin List', - type: 'boolean', - }) .option('verbose', { describe: 'Show plugin manifest path list', type: 'boolean', diff --git a/client/shared/model/plugin.ts b/client/shared/model/plugin.ts index 019105f4..3d886952 100644 --- a/client/shared/model/plugin.ts +++ b/client/shared/model/plugin.ts @@ -6,6 +6,7 @@ export interface PluginManifest { * @example 网页面板插件 */ label: string; + 'label.zh-CN'?: string; /** * 插件名, 插件唯一标识 @@ -42,6 +43,7 @@ export interface PluginManifest { * 插件描述 */ description: string; + 'description.zh-CN'?: string; /** * 是否需要重启才能应用插件 diff --git a/client/web/src/plugin/PluginStore/Item.tsx b/client/web/src/plugin/PluginStore/Item.tsx index b01f5721..40447c08 100644 --- a/client/web/src/plugin/PluginStore/Item.tsx +++ b/client/web/src/plugin/PluginStore/Item.tsx @@ -13,6 +13,7 @@ import { import { ModalWrapper, openModal } from '../common'; import { pluginManager } from '../manager'; import { DocumentView } from './DocumentView'; +import { getManifestFieldWithI18N } from '../utils'; /** * 插件项 @@ -51,27 +52,30 @@ export const PluginStoreItem: React.FC<{ } openModal( - + ); }, [manifest]); + const label = getManifestFieldWithI18N(manifest, 'label'); + const description = getManifestFieldWithI18N(manifest, 'description'); + return (
- +
-
{manifest.label}
+
{label}
{manifest.name}
-
{manifest.description}
+
{description}
{isValidStr(manifest.documentUrl) && ( diff --git a/client/web/src/plugin/builtin.ts b/client/web/src/plugin/builtin.ts index b8acb1df..3e3133e2 100644 --- a/client/web/src/plugin/builtin.ts +++ b/client/web/src/plugin/builtin.ts @@ -13,40 +13,50 @@ const isOffical = [ */ export const builtinPlugins: PluginManifest[] = _compact([ { - label: '网页面板插件', + label: 'Web Panel Plugin', + 'label.zh-CN': '网页面板插件', name: 'com.msgbyte.webview', url: '/plugins/com.msgbyte.webview/index.js', version: '0.0.0', author: 'msgbyte', - description: '为群组提供创建网页面板的功能', + description: 'Provides groups with the ability to create web panels', + 'description.zh-CN': '为群组提供创建网页面板的功能', documentUrl: '/plugins/com.msgbyte.webview/README.md', requireRestart: false, }, { - label: 'BBCode', + label: 'BBCode Mmessage Interpreter', + 'label.zh-CN': 'BBCode 消息解释器', name: 'com.msgbyte.bbcode', - url: '/plugins/com.msgbyte.bbcode/index.js', + url: '/plugins/com.msgbyte.miaolang/index.js', version: '0.0.0', author: 'msgbyte', - description: 'BBCode 格式消息内容解析', + description: + 'A plugin for supporting bbcode syntax to interpret rich text messages', + 'description.zh-CN': '一个用于支持bbcode语法解释富文本消息的插件', requireRestart: true, }, { - label: '消息通知插件', + label: 'Message notification plugin', + 'label.zh-CN': '消息通知插件', name: 'com.msgbyte.notify', url: '/plugins/com.msgbyte.notify/index.js', version: '0.0.0', author: 'msgbyte', - description: '为应用增加通知的能力', + description: 'Ability to add notifications to apps', + 'description.zh-CN': '为应用增加通知的能力', requireRestart: true, }, { - label: '初始引导插件', + label: 'Intro plugin', + 'label.zh-CN': '初始引导插件', name: 'com.msgbyte.intro', url: '/plugins/com.msgbyte.intro/index.js', version: '0.0.0', author: 'msgbyte', - description: '为应用首次打开介绍应用的能力', + description: + 'Turn on the ability to introduce the app for the first time for the app', + 'description.zh-CN': '为应用首次打开介绍应用的能力', requireRestart: true, }, // isOffical @@ -57,7 +67,8 @@ export const builtinPlugins: PluginManifest[] = _compact([ icon: '/plugins/com.msgbyte.posthog/assets/icon.png', version: '0.0.0', author: 'moonrailgun', - description: 'Posthog 数据统计', + description: 'Posthog Statistics', + 'description.zh-CN': 'Posthog 数据统计', requireRestart: true, }, isOffical && { @@ -67,16 +78,19 @@ export const builtinPlugins: PluginManifest[] = _compact([ icon: '/plugins/com.msgbyte.sentry/assets/icon.png', version: '0.0.0', author: 'moonrailgun', - description: 'Sentry 错误处理', + description: 'Sentry error handling', + 'description.zh-CN': 'Sentry 错误处理', requireRestart: true, }, isOffical && { - label: '用户地理位置', + label: 'User Location', + 'label.zh-CN': '用户地理位置', name: 'com.msgbyte.user.location', url: '/plugins/com.msgbyte.user.location/index.js', version: '0.0.0', author: 'moonrailgun', - description: '为用户信息增加地理位置记录', + description: 'Add geographic location records for user information', + 'description.zh-CN': '为用户信息增加地理位置记录', requireRestart: true, }, ]); diff --git a/client/web/src/plugin/utils.ts b/client/web/src/plugin/utils.ts index 7782c480..6c19c394 100644 --- a/client/web/src/plugin/utils.ts +++ b/client/web/src/plugin/utils.ts @@ -1,4 +1,10 @@ -import { isValidJson, parseUrlStr, PluginManifest, t } from 'tailchat-shared'; +import { + isValidJson, + parseUrlStr, + PluginManifest, + t, + getLanguage, +} from 'tailchat-shared'; import { Validator } from 'jsonschema'; /** @@ -41,3 +47,18 @@ export function parsePluginManifest(json: string): PluginManifest { return obj; } + +/** + * Get manifest field with i18n support, + * for example: get `label.zh-CN` than `label` in zh-CN language. + * @param info Plugin Manifest Info + * @param field Plugin Manifest Field + */ +export function getManifestFieldWithI18N( + info: PluginManifest, + field: 'label' | 'description' +): string { + const language = getLanguage(); + + return (info as any)[`${field}.${language}`] ?? info[field]; +}