forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d465d6
commit 3c0117e
Showing
32 changed files
with
253 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"search": { | ||
"placeholder": "Search assistant..." | ||
} | ||
}, | ||
"submitAgent": "Submit Assistant" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"search": { | ||
"placeholder": "Поиск помощника..." | ||
} | ||
}, | ||
"submitAgent": "Отправить агента" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,106 @@ | ||
{} | ||
{ | ||
"debug": { | ||
"arguments": "Аргументы вызова", | ||
"function_call": "Вызов функции", | ||
"response": "Ответ" | ||
}, | ||
"dev": { | ||
"confirmDeleteDevPlugin": "Вы собираетесь удалить этот локальный плагин. После удаления его будет невозможно восстановить. Вы уверены, что хотите удалить этот плагин?", | ||
"deleteSuccess": "Плагин успешно удален", | ||
"manifest": { | ||
"identifier": { | ||
"desc": "Уникальный идентификатор плагина", | ||
"label": "Идентификатор" | ||
}, | ||
"mode": { | ||
"local": "Визуальная настройка", | ||
"local-tooltip": "Визуальная настройка временно недоступна", | ||
"url": "Онлайн-ссылка" | ||
}, | ||
"name": { | ||
"desc": "Заголовок плагина", | ||
"label": "Заголовок", | ||
"placeholder": "Поиск в поисковой системе" | ||
} | ||
}, | ||
"meta": { | ||
"author": { | ||
"desc": "Автор плагина", | ||
"label": "Автор" | ||
}, | ||
"avatar": { | ||
"desc": "Иконка плагина, можно использовать Emoji или URL", | ||
"label": "Иконка" | ||
}, | ||
"description": { | ||
"desc": "Описание плагина", | ||
"label": "Описание", | ||
"placeholder": "Получение информации из поисковой системы" | ||
}, | ||
"formFieldRequired": "Это обязательное поле", | ||
"homepage": { | ||
"desc": "Домашняя страница плагина", | ||
"label": "Домашняя страница" | ||
}, | ||
"identifier": { | ||
"desc": "Уникальный идентификатор плагина, будет автоматически определен из манифеста", | ||
"errorDuplicate": "Идентификатор уже используется другим плагином. Пожалуйста, измените идентификатор", | ||
"label": "Идентификатор", | ||
"pattenErrorMessage": "Можно вводить только латинские буквы, цифры, - и _" | ||
}, | ||
"manifest": { | ||
"desc": "LobeChat будет устанавливать плагин по этой ссылке", | ||
"jsonInvalid": "Манифест не соответствует стандарту. Результат проверки: \n\n {{error}}", | ||
"label": "URL-адрес описания плагина", | ||
"preview": "Предварительный просмотр манифеста", | ||
"refresh": "Обновить", | ||
"requestError": "Не удалось получить данные по этой ссылке. Пожалуйста, введите действительную ссылку и проверьте, разрешен ли кросс-доменный доступ", | ||
"urlError": "Ссылка не возвращает данные в формате JSON. Пожалуйста, введите действительную ссылку" | ||
}, | ||
"title": { | ||
"desc": "Заголовок плагина", | ||
"label": "Заголовок", | ||
"placeholder": "Поиск в поисковой системе" | ||
} | ||
}, | ||
"metaConfig": "Настройка метаданных плагина", | ||
"modalDesc": "После добавления пользовательского плагина его можно использовать для проверки разработки плагинов или непосредственно в сеансе. См. документацию по разработке плагинов", | ||
"preview": { | ||
"card": "Предварительный просмотр плагина", | ||
"desc": "Предварительный просмотр описания плагина", | ||
"title": "Предварительный просмотр имени плагина" | ||
}, | ||
"save": "Сохранить", | ||
"saveSuccess": "Настройки плагина успешно сохранены", | ||
"tabs": { | ||
"manifest": "Описание функций (Манифест)", | ||
"meta": "Метаданные плагина" | ||
}, | ||
"title": "Добавить пользовательский плагин", | ||
"update": "Обновить", | ||
"updateSuccess": "Настройки плагина успешно обновлены" | ||
}, | ||
"list": { | ||
"item": { | ||
"deprecated.title": "Удалено", | ||
"local.config": "Настройка", | ||
"local.title": "Пользовательский" | ||
} | ||
}, | ||
"loading": { | ||
"content": "Получение данных...", | ||
"plugin": "Выполнение плагина..." | ||
}, | ||
"pluginList": "Список плагинов", | ||
"plugins": { | ||
"unknown": "Проверка плагинов..." | ||
}, | ||
"settings": { | ||
"indexUrl": { | ||
"title": "Индекс рынка", | ||
"tooltip": "Редактирование в настоящее время недоступно" | ||
}, | ||
"modalDesc": "После настройки адреса рынка плагинов можно использовать пользовательский рынок плагинов", | ||
"title": "Настройки рынка плагинов" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"search": { | ||
"placeholder": "搜索助手..." | ||
} | ||
}, | ||
"submitAgent": "提交助手" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { readdirSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import i18nConfig from '../.i18nrc'; | ||
|
||
export const root = resolve(__dirname, '..'); | ||
export const localesDir = resolve(root, i18nConfig.output); | ||
export const localeDir = (locale: string) => resolve(localesDir, locale); | ||
export const localeDirJsonList = (locale: string) => | ||
readdirSync(localeDir(locale)).filter((name) => name.includes('.json')); | ||
export const srcLocalesDir = resolve(root, './src/locales'); | ||
export const entryLocaleJsonFilepath = (file: string) => | ||
resolve(localesDir, i18nConfig.entryLocale, file); | ||
export const outputLocaleJsonFilepath = (locale: string, file: string) => | ||
resolve(localesDir, locale, file); | ||
export const srcLocalesResources = resolve(root, srcLocalesDir, 'resources'); | ||
export const localesResourcesFilepath = (locale: string) => resolve(srcLocalesResources, locale); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { consola } from 'consola'; | ||
import { colors } from 'consola/utils'; | ||
import fs from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import i18nConfig from '../.i18nrc'; | ||
import { entryLocaleJsonFilepath, localesResourcesFilepath } from './const'; | ||
import { writeJSON } from './utils'; | ||
|
||
export const genDefaultLocale = (input: string) => { | ||
export const genDefaultLocale = () => { | ||
consola.info(`Default locale is ${i18nConfig.entryLocale}...`); | ||
const resources = require(`../${input}/${i18nConfig.entryLocale}`); | ||
|
||
const resources = require(localesResourcesFilepath(i18nConfig.entryLocale)); | ||
const data = Object.entries(resources.default); | ||
consola.start(`Generate default locale json, found ${data.length} namespaces...`); | ||
|
||
for (const [ns, value] of data) { | ||
const filepath = resolve(i18nConfig.output, i18nConfig.entryLocale, `${ns}.json`); | ||
fs.writeFileSync(filepath, JSON.stringify(value, null, 2)); | ||
const filepath = entryLocaleJsonFilepath(`${ns}.json`); | ||
writeJSON(filepath, value); | ||
consola.success(colors.bgWhiteBright(colors.black(` ${ns} `)), colors.gray(filepath)); | ||
} | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,27 @@ | ||
import { consola } from 'consola'; | ||
import { colors } from 'consola/utils'; | ||
import { tocForResources } from 'i18next-resources-for-ts'; | ||
import fs from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import i18nConfig from '../.i18nrc.js'; | ||
import { localeDirJsonList, localesResourcesFilepath } from './const'; | ||
import { genResourcesContent, genToc } from './utils'; | ||
|
||
const locales = [i18nConfig.entryLocale, ...i18nConfig.outputLocales]; | ||
export const genResources = (output: string) => { | ||
let index = ''; | ||
let indexObj = ''; | ||
|
||
export const genResources = () => { | ||
consola.start(`Generate locale resources and types, found ${locales.length} locales...`); | ||
|
||
for (const locale of locales) { | ||
const files = fs | ||
.readdirSync(resolve(i18nConfig.output, locale)) | ||
.filter((name) => name.includes('.json')); | ||
index += `import ${locale} from "./${locale}";\n`; | ||
indexObj += ` "${locale.replace('_', '-')}": ${locale},\n`; | ||
const ns = []; | ||
for (const file of files) { | ||
ns.push({ | ||
name: file.replace('.json', ''), | ||
path: resolve(i18nConfig.output, locale, file), | ||
}); | ||
} | ||
let toc = tocForResources(ns, resolve(output)).replaceAll('\\', '/'); | ||
if (locale === i18nConfig.entryLocale) { | ||
toc = toc.replaceAll('.json', '').replaceAll('../../../locales/zh_CN', '../default'); | ||
} | ||
const filepath = resolve(output, `${locale}.ts`); | ||
const files = localeDirJsonList(locale); | ||
const toc = genToc(files, locale); | ||
|
||
const filepath = localesResourcesFilepath(`${locale}.ts`); | ||
fs.writeFileSync(filepath, toc); | ||
consola.success(colors.bgBlue(colors.black(` ${locale} `)), colors.gray(filepath)); | ||
} | ||
const indexFilepath = resolve(output, `index.ts`); | ||
fs.writeFileSync( | ||
indexFilepath, | ||
`${index} | ||
const resources = { | ||
${indexObj}} as const; | ||
export default resources; | ||
export const defaultResources = ${i18nConfig.entryLocale}; | ||
export type Resources = typeof resources; | ||
export type DefaultResources = typeof defaultResources; | ||
export type Namespaces = keyof DefaultResources; | ||
export type Locales = keyof Resources; | ||
`, | ||
); | ||
|
||
const indexFilepath = localesResourcesFilepath(`index.ts`); | ||
fs.writeFileSync(indexFilepath, genResourcesContent(locales)); | ||
|
||
consola.success(colors.bgGreen(colors.black(` INDEX `)), colors.gray(indexFilepath)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import { genDefaultLocale } from './genDefaultLocale'; | ||
import { genResources } from './genResources'; | ||
|
||
const RES_OUTPUT = 'src/locales/resources'; | ||
|
||
genDefaultLocale(RES_OUTPUT); | ||
genResources(RES_OUTPUT); | ||
genDefaultLocale(); | ||
genResources(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { tocForResources } from 'i18next-resources-for-ts'; | ||
import { readFileSync, writeFileSync } from 'node:fs'; | ||
import { resolve } from 'node:path'; | ||
|
||
import i18nConfig from '../.i18nrc'; | ||
import { srcLocalesResources } from './const'; | ||
|
||
export const readJSON = (filePath: string) => { | ||
const data = readFileSync(filePath, 'utf8'); | ||
return JSON.parse(data); | ||
}; | ||
|
||
export const writeJSON = (filePath: string, data: any) => { | ||
const jsonStr = JSON.stringify(data, null, 2); | ||
writeFileSync(filePath, jsonStr, 'utf8'); | ||
}; | ||
|
||
export const genResourcesContent = (locales: string[]) => { | ||
let index = ''; | ||
let indexObj = ''; | ||
|
||
for (const locale of locales) { | ||
index += `import ${locale} from "./${locale}";\n`; | ||
indexObj += ` "${locale.replace('_', '-')}": ${locale},\n`; | ||
} | ||
|
||
return `${index} | ||
const resources = { | ||
${indexObj}} as const; | ||
export default resources; | ||
export const defaultResources = ${i18nConfig.entryLocale}; | ||
export type Resources = typeof resources; | ||
export type DefaultResources = typeof defaultResources; | ||
export type Namespaces = keyof DefaultResources; | ||
export type Locales = keyof Resources; | ||
`; | ||
}; | ||
|
||
export const genNamespaceList = (files: string[], locale: string) => { | ||
return files.map((file) => ({ | ||
name: file.replace('.json', ''), | ||
path: resolve(i18nConfig.output, locale, file), | ||
})); | ||
}; | ||
|
||
export const genToc = (files: string[], locale: string) => { | ||
const ns = genNamespaceList(files, locale); | ||
let toc = tocForResources(ns, srcLocalesResources).replaceAll('\\', '/'); | ||
if (locale === i18nConfig.entryLocale) { | ||
toc = toc.replaceAll('.json', '').replaceAll('../../../locales/zh_CN', '../default'); | ||
} | ||
return toc; | ||
}; |
Oops, something went wrong.