Skip to content

Commit

Permalink
✨ feat: Update localization paths, add new files, settings, descripti…
Browse files Browse the repository at this point in the history
…ons, generate TOC, modify imports/exports, define types (lobehub#11)

This commit introduces new localization paths, adds new localization files, adds new settings and descriptions, generates a table of contents, modifies file imports and exports, and defines types for localization resources.

Changes:
- Updated localization paths
- Added new localization files
- Added new settings and descriptions
- Generated a table of contents
- Modified file imports and exports
- Defined types for localization resources
  • Loading branch information
canisminor1990 committed Jul 18, 2023
1 parent 455a1f7 commit 579a0bf
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 190 deletions.
4 changes: 2 additions & 2 deletions .i18nrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const { defineConfig } = require('@lobehub/i18n-cli');

module.exports = defineConfig({
reference: description,
entry: 'public/locales/zh_CN',
entry: 'locales/zh_CN',
entryLocale: 'zh_CN',
output: 'public/locales',
output: 'locales',
outputLocales: ['en_US'],
splitToken: 2500,
temperature: 0,
Expand Down
40 changes: 40 additions & 0 deletions locales/en_US/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"advanceSettings": "Advanced Settings",
"agentAvatar": "Avatar",
"agentDescription": "Description",
"agentDescriptionPlaceholder": "Please enter a description",
"agentModel": "Model",
"agentName": "Name",
"agentNamePlaceholder": "Please enter a name",
"agentProfile": "Agent Profile",
"agentPrompt": "AI Prompt",
"agentPromptPlaceholder": "Please enter AI prompt",
"agentTag": "Tag",
"agentTagPlaceholder": "Please enter a tag",
"archive": "Archive",
"autoGenerate": "Auto Generate",
"cancel": "Cancel",
"close": "Close",
"confirmRemoveSessionItemAlert": "You are about to remove this agent. Once removed, it cannot be recovered. Please confirm your action.",
"defaultAgent": "Default Agent",
"edit": "Edit",
"editAgentProfile": "Edit Agent Profile",
"export": "Export",
"gpt-3.5-turbo": "GPT 3.5 Turbo",
"gpt-3.5-turbo-16k": "GPT 3.5 Turbo (16K)",
"gpt-4": "GPT 4",
"gpt-4-32k": "GPT 4 (32K)",
"modelConfig": "Model Configuration",
"modelTemperature": "Temperature",
"newAgent": "New Agent",
"noDescription": "No description",
"ok": "OK",
"profile": "Profile",
"reset": "Reset",
"searchAgentPlaceholder": "Search agents and conversations...",
"sessionSetting": "Session Setting",
"setting": "Setting",
"share": "Share",
"updateAgent": "Update Agent",
"updatePrompt": "Update Prompt"
}
97 changes: 97 additions & 0 deletions locales/en_US/setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"danger": {
"reset": {
"title": "Reset All Settings",
"desc": "Reset all settings to default values",
"action": "Reset Now",
"confirm": "Confirm reset all settings?",
"currentVersion": "Current Version"
},
"clear": {
"title": "Clear All Data",
"desc": "Clear all chat and settings data",
"action": "Clear Now",
"confirm": "Confirm clear all chat and settings data?"
}
},
"header": "Settings",
"settingChat": {
"title": "Chat Settings",
"inputTemplate": {
"title": "User Input Template",
"desc": "The latest user message will be filled into this template"
},
"compressThreshold": {
"title": "History Message Length Compression Threshold",
"desc": "When the uncompressed history message exceeds this value, it will be compressed"
},
"historyCount": {
"title": "Number of History Messages",
"desc": "Number of history messages carried in each request"
},
"maxTokens": {
"title": "Max Tokens per Response",
"desc": "The maximum number of tokens used for each interaction"
},
"sendKey": {
"title": "Send Key"
}
},
"settingModel": {
"title": "Model Settings",
"model": {
"title": "Model"
},
"temperature": {
"title": "Randomness (temperature)",
"desc": "The higher the value, the more random the response"
},
"topP": {
"title": "Nucleus Sampling (top_p)",
"desc": "Similar to randomness, but do not change it together with randomness"
},
"presencePenalty": {
"title": "Topic Freshness (presence_penalty)",
"desc": "The higher the value, the more likely it is to expand to new topics"
},
"frequencyPenalty": {
"title": "Frequency Penalty (frequency_penalty)",
"desc": "The higher the value, the more likely it is to reduce repeated words"
}
},
"settingOpenAI": {
"title": "OpenAI Settings",
"token": {
"title": "API Key",
"desc": "Use your own key to bypass password access restrictions",
"placeholder": "OpenAI API Key"
},
"endpoint": {
"title": "API Endpoint",
"desc": "In addition to the default address, it must include http(s)://"
}
},
"settingSystem": {
"title": "System Settings",
"accessCode": {
"title": "Access Code",
"desc": "Encryption access has been enabled by the administrator",
"placeholder": "Please enter the access code"
}
},
"settingTheme": {
"title": "Theme Settings",
"avatar": {
"title": "Avatar",
"desc": "Supports URL / Base64 / Emoji"
},
"fontSize": {
"title": "Font Size",
"desc": "Font size of chat content"
},
"lang": {
"name": "Language Settings",
"all": "All Languages"
}
}
}
40 changes: 40 additions & 0 deletions locales/zh_CN/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"advanceSettings": "高级设置",
"agentAvatar": "头像",
"agentDescription": "描述",
"agentDescriptionPlaceholder": "请输入描述",
"agentModel": "模型",
"agentName": "名称",
"agentNamePlaceholder": "请输入名称",
"agentProfile": "助手信息",
"agentPrompt": "提示词",
"agentPromptPlaceholder": "请输入 AI 提示词",
"agentTag": "标签",
"agentTagPlaceholder": "请输入标签",
"archive": "归档",
"autoGenerate": "自动补全",
"cancel": "取消",
"close": "关闭",
"confirmRemoveSessionItemAlert": "即将删除该助手,删除后该将无法找回,请确认你的操作",
"defaultAgent": "默认助手",
"edit": "编辑",
"editAgentProfile": "编辑助手信息",
"export": "导出",
"gpt-3.5-turbo": "GPT 3.5",
"gpt-3.5-turbo-16k": "GPT 3.5 (16K)",
"gpt-4": "GPT 4",
"gpt-4-32k": "GPT 4 (32K)",
"modelConfig": "模型配置",
"modelTemperature": "发散度",
"newAgent": "新建助手",
"noDescription": "暂无描述",
"ok": "确定",
"profile": "身份卡",
"reset": "重置",
"searchAgentPlaceholder": "搜索助手和对话...",
"sessionSetting": "会话设置",
"setting": "设置",
"share": "分享",
"updateAgent": "更新助理信息",
"updatePrompt": "更新提示词"
}
98 changes: 98 additions & 0 deletions locales/zh_CN/setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"danger": {
"reset": {
"title": "重置所有设置",
"desc": "重置所有设置项回默认值",
"action": "立即重置",
"confirm": "确认重置所有设置?",
"currentVersion": "当前版本"
},
"clear": {
"title": "清除所有数据",
"desc": "清除所有聊天、设置数据",
"action": "立即清除",
"confirm": "确认清除所有聊天、设置数据?"
}
},

"header": "设置",
"settingChat": {
"title": "聊天设置",
"inputTemplate": {
"title": "用户输入预处理",
"desc": "用户最新的一条消息会填充到此模板"
},
"compressThreshold": {
"title": "历史消息长度压缩阈值",
"desc": "当未压缩的历史消息超过该值时,将进行压缩"
},
"historyCount": {
"title": "附带历史消息数",
"desc": "每次请求携带的历史消息数"
},
"maxTokens": {
"title": "单次回复限制 (max_tokens)",
"desc": "单次交互所用的最大 Token 数"
},
"sendKey": {
"title": "发送键"
}
},
"settingModel": {
"title": "模型设置",
"model": {
"title": "模型"
},
"temperature": {
"title": "随机性 (temperature)",
"desc": "值越大,回复越随机"
},
"topP": {
"title": "核采样 (top_p)",
"desc": "与随机性类似,但不要和随机性一起更改"
},
"presencePenalty": {
"title": "话题新鲜度 (presence_penalty)",
"desc": "值越大,越有可能扩展到新话题"
},
"frequencyPenalty": {
"title": "频率惩罚度 (frequency_penalty)",
"desc": "值越大,越有可能降低重复字词"
}
},
"settingOpenAI": {
"title": "OpenAI 设置",
"token": {
"title": "API Key",
"desc": "使用自己的 Key 可绕过密码访问限制",
"placeholder": "OpenAI API Key"
},
"endpoint": {
"title": "接口地址",
"desc": "除默认地址外,必须包含 http(s)://"
}
},
"settingSystem": {
"title": "系统设置",
"accessCode": {
"title": "访问密码",
"desc": "管理员已开启加密访问",
"placeholder": "请输入访问密码"
}
},
"settingTheme": {
"title": "主题设置",
"avatar": {
"title": "头像",
"desc": "支持 URL / Base64 / Emoji 表情符号"
},
"fontSize": {
"title": "字体大小",
"desc": "聊天内容的字体大小"
},
"lang": {
"name": "语言设置",
"all": "所有语言"
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"test": "vitest --passWithNoTests",
"test:coverage": "vitest run --coverage --passWithNoTests",
"test:update": "vitest -u",
"toc": "i18next-resources-for-ts toc -i ./public/locales/zh_CN -o ./src/types/resources.ts",
"toc": "node scripts/toc.mjs",
"type-check": "tsc --noEmit"
},
"lint-staged": {
Expand Down
12 changes: 12 additions & 0 deletions scripts/genDefaultLocale.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'node:fs';
import { resolve } from 'node:path';

import i18nConfig from '../.i18nrc.js';
import resources from '../src/locales/resources/zh_CN.ts';

for (const [ns, value] of Object.entries(resources)) {
fs.writeFileSync(
resolve(i18nConfig.output, i18nConfig.entryLocale, `${ns}.json`),
JSON.stringify(value, null, 2),
);
}
40 changes: 40 additions & 0 deletions scripts/toc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { tocForResources } from 'i18next-resources-for-ts';
import fs from 'node:fs';
import { resolve } from 'node:path';

import i18nConfig from '../.i18nrc.js';

const locales = [i18nConfig.entryLocale, ...i18nConfig.outputLocales];

const RES_OUTPUT = 'src/locales/resources';

let index = '';
let indexObj = '';
locales.forEach((locale) => {
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 = [];
files.forEach((file) => {
ns.push({
name: file.replace('.json', ''),
path: resolve(i18nConfig.output, locale, file),
});
});
let toc = tocForResources(ns, resolve(RES_OUTPUT)).replaceAll('\\', '/');
if (locale === i18nConfig.entryLocale) {
toc = toc.replaceAll('.json', '').replaceAll('../../../locales/zh_CN', '../default');
}
fs.writeFileSync(resolve(RES_OUTPUT, `${locale}.ts`), toc);
});

fs.writeFileSync(
resolve(RES_OUTPUT, `index.ts`),
`${index}
export default {
${indexObj}};
`,
);
Loading

0 comments on commit 579a0bf

Please sign in to comment.