mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-20 09:20:59 +00:00
perf: add supports for showing multilingual plugin README
This commit is contained in:
+8
-3
@@ -11,7 +11,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { PluginV4 } from '@/app/infra/entities/plugin';
|
import { PluginV4 } from '@/app/infra/entities/plugin';
|
||||||
import { getCloudServiceClientSync } from '@/app/infra/http';
|
import { getCloudServiceClientSync } from '@/app/infra/http';
|
||||||
import { extractI18nObject } from '@/i18n/I18nProvider';
|
import { extractI18nObject, getAPILanguageCode } from '@/i18n/I18nProvider';
|
||||||
import PluginComponentList from '@/app/home/plugins/components/plugin-installed/PluginComponentList';
|
import PluginComponentList from '@/app/home/plugins/components/plugin-installed/PluginComponentList';
|
||||||
|
|
||||||
interface PluginDetailDialogProps {
|
interface PluginDetailDialogProps {
|
||||||
@@ -54,11 +54,16 @@ export default function PluginDetailDialog({
|
|||||||
);
|
);
|
||||||
setPlugin(detailResponse.plugin);
|
setPlugin(detailResponse.plugin);
|
||||||
|
|
||||||
// 获取README
|
// 获取README,根据当前语言设置传递language参数
|
||||||
setIsLoadingReadme(true);
|
setIsLoadingReadme(true);
|
||||||
try {
|
try {
|
||||||
|
const languageCode = getAPILanguageCode();
|
||||||
const readmeResponse =
|
const readmeResponse =
|
||||||
await getCloudServiceClientSync().getPluginREADME(author, pluginName);
|
await getCloudServiceClientSync().getPluginREADME(
|
||||||
|
author,
|
||||||
|
pluginName,
|
||||||
|
languageCode,
|
||||||
|
);
|
||||||
setReadme(readmeResponse.readme);
|
setReadme(readmeResponse.readme);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to load README:', error);
|
console.warn('Failed to load README:', error);
|
||||||
|
|||||||
@@ -61,9 +61,11 @@ export class CloudServiceClient extends BaseHttpClient {
|
|||||||
public getPluginREADME(
|
public getPluginREADME(
|
||||||
author: string,
|
author: string,
|
||||||
pluginName: string,
|
pluginName: string,
|
||||||
|
language?: string,
|
||||||
): Promise<{ readme: string }> {
|
): Promise<{ readme: string }> {
|
||||||
return this.get<{ readme: string }>(
|
return this.get<{ readme: string }>(
|
||||||
`/api/v1/marketplace/plugins/${author}/${pluginName}/resources/README`,
|
`/api/v1/marketplace/plugins/${author}/${pluginName}/resources/README`,
|
||||||
|
language ? { language } : undefined,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,3 +37,20 @@ export const extractI18nObject = (i18nObject: I18nObject): string => {
|
|||||||
''
|
''
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 工具函数:将 i18n 语言代码转换为 API 语言代码
|
||||||
|
// i18n 使用:zh-Hans, en-US, ja-JP
|
||||||
|
// API 使用:zh_Hans, en, ja_JP
|
||||||
|
export const getAPILanguageCode = (): string => {
|
||||||
|
const language = i18n.language;
|
||||||
|
// zh-Hans -> zh_Hans
|
||||||
|
if (language === 'zh-Hans') return 'zh_Hans';
|
||||||
|
// zh-Hant -> zh_Hant
|
||||||
|
if (language === 'zh-Hant') return 'zh_Hant';
|
||||||
|
// en-US -> en
|
||||||
|
if (language === 'en-US') return 'en';
|
||||||
|
// ja-JP -> ja_JP
|
||||||
|
if (language === 'ja-JP') return 'ja_JP';
|
||||||
|
// 默认返回 en
|
||||||
|
return 'en';
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user