Skip to content

Commit

Permalink
✨ feat: 适配插件 i18n 方案
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Sep 9, 2023
1 parent a0603a9 commit 8709ab3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/const/url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Locales } from '@/locales/resources';

import pkg from '../../package.json';
import { INBOX_SESSION_ID } from './session';

Expand All @@ -8,7 +10,13 @@ export const FEEDBACK = pkg.bugs.url;
export const DISCORD = 'https://discord.gg/AYFPHvv2jT';

export const PLUGINS_INDEX_URL =
process.env.PLUGINS_INDEX_URL ?? 'https://chat-plugins.lobehub.com';
process.env.PLUGINS_INDEX_URL ?? 'https://chat-plugins.lobehub.com/index';

export const getPluginIndexJSON = (lang: Locales = 'en-US', baseUrl = PLUGINS_INDEX_URL) => {
if (lang === 'en-US') return baseUrl;

return `${baseUrl}.${lang}.json`;
};

export const AGENTS_INDEX_URL = process.env.AGENTS_INDEX_URL ?? 'https://chat-agents.lobehub.com';

Expand Down
7 changes: 5 additions & 2 deletions src/services/pluginMarket.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { PLUGINS_INDEX_URL } from '@/const/url';
import { getPluginIndexJSON } from '@/const/url';
import { useGlobalStore } from '@/store/global';

/**
* 请求插件列表
*/
export const getPluginList = async () => {
const res = await fetch(PLUGINS_INDEX_URL);
const url = getPluginIndexJSON(useGlobalStore.getState().settings.language);

const res = await fetch(url);

return res.json();
};

0 comments on commit 8709ab3

Please sign in to comment.