fix(i18n): use English runtime text and localize system UI

This commit is contained in:
Arthur Koba
2026-10-25 19:44:15 +03:00
parent ada0550571
commit 65a96670d5
289 changed files with 8092 additions and 3426 deletions
+159
View File
@@ -0,0 +1,159 @@
#!/usr/bin/env node
// Read-only inventory of all non-ASCII text in tracked and unignored files.
import { execFileSync } from 'node:child_process';
import { readFileSync, mkdirSync, writeFileSync } from 'node:fs';
import { dirname, extname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const output = resolve(root, process.argv[2] ?? '.codex-artifacts/non-english-audit');
const paths = [...new Set(execFileSync('git', ['ls-files', '--cached', '--others', '--exclude-standard', '-z'], { cwd: root, maxBuffer: 16 * 1024 * 1024 }).toString('utf8').split('\0').filter(Boolean))].sort();
const scripts = ['Han', 'Hiragana', 'Katakana', 'Hangul', 'Cyrillic', 'Arabic', 'Hebrew', 'Greek', 'Thai', 'Devanagari', 'Latin'];
const scriptPatterns = scripts.map((name) => [name, new RegExp(`\\p{Script=${name}}`, 'u')]);
const nonASCII = /[^\x00-\x7f]/gu;
const escapes = /\\u\{([0-9a-f]{1,6})\}|\\u([0-9a-f]{4})|\\U([0-9a-f]{8})/gi;
const records = [];
const skipped = [];
let scanned = 0;
function component(path) {
const parts = path.split('/');
if (path.startsWith('frontend/app/')) return parts.slice(0, 5).join('/');
if (path.startsWith('internal/apps/')) return parts.slice(0, 3).join('/');
return parts.slice(0, Math.min(3, parts.length - 1)).join('/') || '.';
}
// Comments are classified lexically; ambiguous source remains a review candidate.
function commentMask(text, path) {
const extension = extname(path);
const mask = new Uint8Array(text.length);
const slashComments = ['.go', '.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.css', '.scss', '.proto'].includes(extension);
const hashComments = ['.sh', '.yaml', '.yml', '.toml', '.py', '.conf'].includes(extension) || /(^|\/)(\.env[^/]*|\.gitignore|Dockerfile|Makefile)$/.test(path);
let state = '', quote = '';
for (let i = 0; i < text.length; i++) {
const c = text[i], next = text[i + 1];
if (state === 'line') {
mask[i] = 1;
if (c === '\n') state = '';
} else if (state === 'block') {
mask[i] = 1;
if (c === '*' && next === '/') { mask[++i] = 1; state = ''; }
} else if (quote) {
if (c === '\\' && !(extension === '.go' && quote === '`')) i++;
else if (c === quote) quote = '';
} else if (slashComments && c === '/' && next === '/') {
mask[i] = mask[++i] = 1; state = 'line';
} else if (slashComments && c === '/' && next === '*') {
mask[i] = mask[++i] = 1; state = 'block';
} else if (hashComments && c === '#') {
mask[i] = 1; state = 'line';
} else if (c === '"' || c === "'" || (slashComments && c === '`')) quote = c;
}
return mask;
}
function category(path, line, spans, mask, offset) {
if (path.startsWith('frontend/messages/') || /\/locales\//.test(path)) return 'translation-resource';
if (/\.(md|mdx)$/i.test(path)) return 'documentation';
if (['docs/docs.go', 'docs/swagger.json', 'docs/swagger.yaml'].includes(path)) return 'generated-api-documentation';
if (path.startsWith('docs/')) return 'documentation-site';
if (path.startsWith('.agents/') || path === 'scripts/audit-non-english.mjs') return 'developer-tooling';
if (path.startsWith('.auto/')) return 'development-history';
if (path.startsWith('.github/ISSUE_TEMPLATE/') || /close.ticket/i.test(path)) return 'community-template';
if (/(_test\.go|\.(test|spec)\.[^.]+)$/.test(path) || /(^|\/)(tests?|testdata|testhelper)\//.test(path)) return 'test-fixture';
if (path.startsWith('internal/infra/persistence/migrator/goose/')) return 'historical-migration';
if (!spans.some((span) => /\p{L}/u.test(span.value))) return 'symbol-or-typography';
if (spans.every((span) => mask[offset + span.column - 1])) return 'source-comment';
if ((path === 'internal/apps/upload/stats/category.go' || path === 'frontend/app/(main)/admin/files/components/file-stats.tsx' || path === 'frontend/scripts/check-runtime-language.mjs') && spans.every((span) => /^[图片视频音频文档压缩包其他]+$/u.test(span.value))) return 'legacy-identifier';
if (extname(path) === '.go' && /`[^`]*(?:json|gorm|description|example):/.test(line)) return 'schema-metadata';
return 'review-candidate';
}
for (const path of paths) {
// Never include private environment values, even if accidentally tracked.
if (/(^|\/)\.env(?:\.|$)/.test(path) && !/(example|sample|template)/.test(path)) { skipped.push({ path, reason: 'private-environment' }); continue; }
let bytes;
try { bytes = readFileSync(resolve(root, path)); } catch (error) { skipped.push({ path, reason: error.code }); continue; }
let text;
try {
if (bytes[0] === 0xff && bytes[1] === 0xfe) text = new TextDecoder('utf-16le', { fatal: true }).decode(bytes);
else if (bytes[0] === 0xfe && bytes[1] === 0xff) text = new TextDecoder('utf-16be', { fatal: true }).decode(bytes);
else {
if (bytes.includes(0)) { skipped.push({ path, reason: 'binary' }); continue; }
text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
}
} catch { skipped.push({ path, reason: 'non-utf8-or-binary' }); continue; }
scanned++;
const mask = commentMask(text, path);
let offset = 0, lineNumber = 0;
for (const line of text.split('\n')) {
lineNumber++;
const spans = [...line.matchAll(nonASCII)].map((match) => ({ column: match.index + 1, value: match[0], escaped: false }));
for (const match of line.matchAll(escapes)) {
const code = parseInt(match[1] ?? match[2] ?? match[3], 16);
if (code > 127 && code <= 0x10ffff) spans.push({ column: match.index + 1, value: String.fromCodePoint(code), escaped: true });
}
if (spans.length) {
spans.sort((a, b) => a.column - b.column);
const characters = [...new Set(spans.map((span) => span.value))];
const names = scriptPatterns.filter(([, pattern]) => characters.some((c) => pattern.test(c))).map(([name]) => name);
if (characters.some((c) => /\p{L}/u.test(c) && !scriptPatterns.some(([, pattern]) => pattern.test(c)))) names.push('Other-letter');
records.push({ path, line: lineNumber, component: component(path), category: category(path, line, spans, mask, offset), scripts: names, codepoints: characters.map((c) => `U+${c.codePointAt(0).toString(16).toUpperCase().padStart(4, '0')}`), spans, text: line.replace(/\r$/, '') });
}
offset += line.length + 1;
}
if (nonASCII.test(path)) records.push({ path, line: 0, component: component(path), category: 'non-ascii-path', scripts: [], codepoints: [], spans: [], text: path });
nonASCII.lastIndex = 0;
}
mkdirSync(output, { recursive: true });
const totals = {};
for (const record of records) totals[record.category] = (totals[record.category] ?? 0) + 1;
const candidates = records.filter((record) => record.category === 'review-candidate');
const decisions = {
'translation-resource': 'Keep in locale resources; expected localized content.',
documentation: 'Keep: project policy requires Chinese documentation.',
'generated-api-documentation': 'Keep: generated Chinese API documentation, not runtime log or UI literals.',
'documentation-site': 'Keep: Chinese documentation navigation, locale names and documentation assets.',
'developer-tooling': 'Keep: agent instructions, examples and audit policy; outside application runtime.',
'development-history': 'Keep: development history, not imported by application code.',
'community-template': 'Keep: upstream Chinese community issue/message templates.',
'test-fixture': 'Keep: test samples and expected Unicode behavior.',
'historical-migration': 'Keep: migration history; do not rewrite applied migrations.',
'source-comment': 'Keep: source comments do not produce runtime text.',
'legacy-identifier': 'Keep: persisted upload category identifiers; display labels use translations.',
'schema-metadata': 'Review separately: schema descriptions/examples, not runtime log messages.',
'symbol-or-typography': 'Keep: punctuation, emoji, math and explicit Unicode/control-character handling.',
'review-candidate': 'Review source: not covered by the classifications above.',
};
const csv = (rows) => '\ufeff' + [['path', 'line', 'component', 'category', 'scripts', 'text'], ...rows.map((r) => [r.path, r.line, r.component, r.category, r.scripts.join(', '), r.text])].map((row) => row.map((cell) => `"${String(cell).replaceAll('"', '""')}"`).join(',')).join('\r\n');
writeFileSync(resolve(output, 'occurrences.json'), JSON.stringify({ coverage: { discovered: paths.length, scanned, skipped, columns: '1-based UTF-16 offsets', scope: 'git ls-files --cached --others --exclude-standard; ignored dependencies, build output and private environment files excluded; binary files are not OCRed or unpacked' }, totals, decisions, records }, null, 2) + '\n');
writeFileSync(resolve(output, 'occurrences.csv'), csv(records));
writeFileSync(resolve(output, 'review-candidates.csv'), csv(candidates));
const groups = new Map();
for (const r of candidates) groups.set(r.component, (groups.get(r.component) ?? 0) + 1);
const components = new Map();
for (const r of records) {
if (!components.has(r.component)) components.set(r.component, { files: new Set(), lines: 0, categories: new Set() });
const group = components.get(r.component);
group.files.add(r.path);
group.lines++;
group.categories.add(r.category);
}
const componentRows = [...components].sort((a, b) => b[1].lines - a[1].lines);
writeFileSync(resolve(output, 'components.json'), JSON.stringify(componentRows.map(([name, group]) => ({ component: name, files: [...group.files].sort(), lines: group.lines, categories: [...group.categories].sort() })), null, 2) + '\n');
writeFileSync(resolve(output, 'summary.md'), [
'# Non-English source inventory', '',
`Text files scanned: **${scanned}** of **${paths.length}** tracked and unignored files. Skipped: **${skipped.length}** (see occurrences.json).`,
`Non-ASCII or escaped Unicode lines: **${records.length}**, in **${new Set(records.map((r) => r.path)).size}** files. Review candidates: **${candidates.length}**.`, '',
'All characters outside ASCII are included, including punctuation, symbols and emoji. Language cannot be inferred reliably from a script (Han may be Chinese or Japanese). Script names describe characters, not detected language.', '',
'Classification is a review aid, not proof that a string executes or reaches a user. Comments, test data, migration history, schemas, community templates and legacy identifiers are retained. No source files are changed by this command.', '',
'Ignored dependencies, generated build output and private environment files are excluded. Binary files (including screenshots, fonts, GeoIP data and archives) are listed as skipped; image text is not OCRed and archives are not unpacked by this command.', '',
'## Categories', '', '| Category | Lines | Disposition |', '| --- | ---: | --- |', ...Object.entries(totals).sort().map(([name, count]) => `| ${name} | ${count} | ${decisions[name] ?? 'Review'} |`), '',
'## Scripts', '', '| Script | Lines |', '| --- | ---: |', ...scripts.concat('Other-letter').map((script) => `| ${script} | ${records.filter((r) => r.scripts.includes(script)).length} |`), '',
'## Components requiring review', '', '| Component | Lines |', '| --- | ---: |', ...[...groups].sort((a, b) => b[1] - a[1]).map(([name, count]) => `| ${name} | ${count} |`), '',
'## Largest components (all categories)', '', '| Component | Lines | Files |', '| --- | ---: | ---: |', ...componentRows.slice(0, 30).map(([name, group]) => `| ${name} | ${group.lines} | ${group.files.size} |`), '',
'## Files', '', '- occurrences.csv: every matching line with its source path and component.', '- occurrences.json: exact character positions, Unicode code points, script classifications and skipped files.', '- components.json: every affected component, its source files, counts and categories.', '- review-candidates.csv: remaining source/configuration candidates, including embedded templates.', '',
'Regenerate from the repository root: `node scripts/audit-non-english.mjs`.', '',
].join('\n'));
console.log(JSON.stringify({ scanned, skipped: skipped.length, lines: records.length, files: new Set(records.map((r) => r.path)).size, totals, output }, null, 2));
+38 -39
View File
@@ -21,33 +21,33 @@ CURRENT_DIR="$(pwd)"
LOG_FILE="${CURRENT_DIR}/install.log"
# Translation text variables
TXT_DOCKER_RESTARTED="Docker 已启动/重启并运行中"
TXT_LOW_DOCKER_VERSION="Docker 版本较低,建议升级到 20.10 及以上版本"
TXT_INSTALL_DOCKER_CONFIRM="未检测到 Docker,是否现在安装?(y/n) [y]: "
TXT_DOCKER_INSTALL_ONLINE="开始在线安装 Docker..."
TXT_INSTALL_DOCKER_ONLINE="使用 opkg 在线安装 Docker..."
TXT_CHOOSE_LOWEST_LATENCY_SOURCE="选择延迟最低的镜像源:"
TXT_CHOOSE_LOWEST_LATENCY_DELAY="延迟为:"
TXT_TRY_NEXT_LINK="尝试使用链接:"
TXT_DOWNLOAD_DOCKER_SCRIPT="下载 Docker 安装脚本..."
TXT_DOWNLOAD_DOCKER_SCRIPT_SUCCESS="下载成功:"
TXT_SUCCESSFULLY_MESSAGE="开始执行安装..."
TXT_DOWNLOAD_FAIELD="下载失败:"
TXT_ALL_DOWNLOAD_ATTEMPTS_FAILED="所有 Docker 下载尝试均失败,请手动安装 Docker"
TXT_DOCKER_INSTALL_FAIL="Docker 安装失败"
TXT_DOCKER_INSTALL_SUCCESS="Docker 安装成功"
TXT_CANNOT_SELECT_SOURCE="无法选择合适的镜像源"
TXT_REGIONS_OTHER_THAN_CHINA="检测到非中国大陆地区,使用官方源安装 Docker..."
TXT_DOCKER_START_NOTICE="正在启动 Docker 服务..."
TXT_CANCEL_INSTALL_DOCKER="已取消 Docker 安装"
TXT_INVALID_YN_INPUT="无效的输入,请输入 y 或 n"
TXT_DOCKER_RESTARTED="Docker is running after startup/restart"
TXT_LOW_DOCKER_VERSION="Docker is outdated; version 20.10 or later is recommended"
TXT_INSTALL_DOCKER_CONFIRM="Docker was not found. Install it now? (y/n) [y]: "
TXT_DOCKER_INSTALL_ONLINE="Starting Docker installation..."
TXT_INSTALL_DOCKER_ONLINE="Installing Docker with opkg..."
TXT_CHOOSE_LOWEST_LATENCY_SOURCE="Selecting the mirror with the lowest latency:"
TXT_CHOOSE_LOWEST_LATENCY_DELAY="Latency:"
TXT_TRY_NEXT_LINK="Trying URL:"
TXT_DOWNLOAD_DOCKER_SCRIPT="Downloading the Docker installation script..."
TXT_DOWNLOAD_DOCKER_SCRIPT_SUCCESS="Download succeeded:"
TXT_SUCCESSFULLY_MESSAGE="Starting installation..."
TXT_DOWNLOAD_FAIELD="Download failed:"
TXT_ALL_DOWNLOAD_ATTEMPTS_FAILED="All Docker download attempts failed; install Docker manually"
TXT_DOCKER_INSTALL_FAIL="Docker installation failed"
TXT_DOCKER_INSTALL_SUCCESS="Docker installed successfully"
TXT_CANNOT_SELECT_SOURCE="Could not select a suitable mirror"
TXT_REGIONS_OTHER_THAN_CHINA="Outside mainland China; installing Docker from the official source..."
TXT_DOCKER_START_NOTICE="Starting the Docker service..."
TXT_CANCEL_INSTALL_DOCKER="Docker installation canceled"
TXT_INVALID_YN_INPUT="Invalid input; enter y or n"
log() {
echo -e "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
configure_accelerator() {
log "配置 Docker 国内镜像加速源..."
log "Configuring Docker mirrors for mainland China..."
local docker_config_folder="/etc/docker"
if [[ ! -d "$docker_config_folder" ]]; then
mkdir -p "$docker_config_folder"
@@ -317,13 +317,12 @@ done
if [[ "$HAS_ARGS" == "false" ]]; then
echo "=================================================="
echo "欢迎使用 OpenFlare Agent 安装脚本"
echo "Welcome to the OpenFlare Agent Installer"
echo "=================================================="
echo "请选择安装方式 / Please choose installation method:"
echo " 1) Local (本地安装: 下载二进制运行,需要本地有 OpenResty)"
echo " 2) Docker (容器安装: 运行内置 OpenResty 的 Agent 容器)"
read -p "请输入序号 [1-2] (默认 1): " method_choice
echo "Please choose an installation method:"
echo " 1) Local (download and run the binary; requires a local OpenResty installation)"
echo " 2) Docker (run the Agent container with OpenResty included)"
read -p "Enter an option [1-2] (default: 1): " method_choice
method_choice=${method_choice:-1}
case "$method_choice" in
2) INSTALL_METHOD="docker" ;;
@@ -336,20 +335,20 @@ if [[ "$HAS_ARGS" == "false" ]]; then
# Prompt for Server URL
while [[ -z "$SERVER_URL" ]]; do
read -p "请输入 OpenFlare Server 地址 (例如 http://127.0.0.1:3000): " SERVER_URL
read -p "Enter the OpenFlare Server URL (for example, http://127.0.0.1:3000): " SERVER_URL
done
# Prompt for Token
while [[ -z "$DISCOVERY_TOKEN" && -z "$AGENT_TOKEN" ]]; do
echo "请选择认证 Token 类型 / Please choose token type:"
echo " 1) Discovery Token (自动注册凭证 - 适合新节点上线)"
echo " 2) Agent Token (专属接入凭证 - 适合预创建节点)"
read -p "请输入序号 [1-2] (默认 1): " token_type_choice
echo "Please choose a token type:"
echo " 1) Discovery Token (automatic registration credentials for new nodes)"
echo " 2) Agent Token (dedicated credentials for pre-created nodes)"
read -p "Enter an option [1-2] (default: 1): " token_type_choice
token_type_choice=${token_type_choice:-1}
if [[ "$token_type_choice" == "2" ]]; then
read -p "请输入 Agent Token: " AGENT_TOKEN
read -p "Enter the Agent Token: " AGENT_TOKEN
else
read -p "请输入 Discovery Token: " DISCOVERY_TOKEN
read -p "Enter the Discovery Token: " DISCOVERY_TOKEN
fi
done
else
@@ -371,13 +370,13 @@ fi
# Run Docker container installation if Docker method selected
if [[ "$INSTALL_METHOD" == "docker" ]]; then
echo "拉取最新的 OpenFlare Agent 镜像..."
echo "Pulling the latest OpenFlare Agent image..."
docker pull ghcr.io/rain-kl/openflare-agent:latest
echo "停止并移除旧的 openflare-agent 容器 (如果存在)..."
echo "Stopping and removing the existing openflare-agent container, if any..."
docker rm -f openflare-agent 2>/dev/null || true
echo "启动 openflare-agent 容器..."
echo "Starting the openflare-agent container..."
if [[ -n "$AGENT_TOKEN" ]]; then
docker run -d --name openflare-agent --restart unless-stopped \
-p 80:80 -p 443:443/tcp -p 443:443/udp \
@@ -395,8 +394,8 @@ if [[ "$INSTALL_METHOD" == "docker" ]]; then
fi
echo ""
echo "OpenFlare Agent (Docker) 安装成功!"
echo "您可以执行以下命令查看运行日志:"
echo "OpenFlare Agent (Docker) installed successfully!"
echo "Run the following command to view runtime logs:"
echo " docker logs -f openflare-agent"
exit 0
fi
@@ -406,7 +405,7 @@ if [[ -z "$OPENRESTY_PATH" ]]; then
if command -v openresty >/dev/null 2>&1; then
OPENRESTY_PATH="$(command -v openresty)"
elif [[ "$HAS_ARGS" == "false" ]]; then
read -p "未在 PATH 中检测到 openresty,请输入 OpenResty 二进制路径: " OPENRESTY_PATH
read -p "OpenResty was not found in PATH. Enter the path to its binary: " OPENRESTY_PATH
if [[ -z "$OPENRESTY_PATH" ]]; then
echo "Error: OpenResty binary path is required for local installation."
exit 1
+13 -14
View File
@@ -56,13 +56,12 @@ done
if [[ "$HAS_ARGS" == "false" ]]; then
echo "=================================================="
echo "欢迎使用 OpenFlare Agent 卸载脚本"
echo "Welcome to the OpenFlare Agent Uninstaller"
echo "=================================================="
echo "请选择卸载方式 / Please choose uninstall method:"
echo " 1) Local (本地卸载: 停止服务并删除二进制及配置)"
echo " 2) Docker (容器卸载: 停止并删除 Docker 容器)"
read -p "请输入序号 [1-2] (默认 1): " method_choice
echo "Please choose an uninstall method:"
echo " 1) Local (stop the service and remove the binary and configuration)"
echo " 2) Docker (stop and remove the Docker container)"
read -p "Enter an option [1-2] (default: 1): " method_choice
method_choice=${method_choice:-1}
case "$method_choice" in
2) INSTALL_METHOD="docker" ;;
@@ -75,39 +74,39 @@ else
fi
if [[ "$INSTALL_METHOD" == "docker" ]]; then
echo "正在卸载 OpenFlare Agent (Docker)..."
echo "Uninstalling OpenFlare Agent (Docker)..."
# Check if container exists
if command -v docker >/dev/null 2>&1; then
if docker ps -a --format '{{.Names}}' | grep -Eq "^openflare-agent$"; then
echo "停止并移除 openflare-agent 容器..."
echo "Stopping and removing the openflare-agent container..."
docker stop openflare-agent || true
docker rm -f openflare-agent || true
echo "已成功移除 openflare-agent 容器。"
echo "The openflare-agent container was removed successfully."
else
echo "未检测到 openflare-agent 容器。"
echo "No openflare-agent container was found."
fi
# In interactive mode, ask if user wants to remove docker image
if [[ "$HAS_ARGS" == "false" ]]; then
read -p "是否删除 OpenFlare Agent 镜像 (ghcr.io/rain-kl/openflare-agent:latest)? (y/n) [n]: " remove_image_choice
read -p "Remove the OpenFlare Agent image (ghcr.io/rain-kl/openflare-agent:latest)? (y/n) [n]: " remove_image_choice
remove_image_choice=${remove_image_choice:-n}
case "$remove_image_choice" in
[yY])
echo "正在删除 Docker 镜像..."
echo "Removing the Docker image..."
docker rmi ghcr.io/rain-kl/openflare-agent:latest || true
;;
*)
echo "保留 Docker 镜像。"
echo "Keeping the Docker image."
;;
esac
fi
else
echo "Error: 未检测到 Docker 运行环境,无法进行 Docker 方式的卸载。"
echo "Error: Docker was not found; cannot uninstall a Docker deployment."
exit 1
fi
echo "OpenFlare Agent (Docker) 卸载完成。"
echo "OpenFlare Agent (Docker) uninstalled."
exit 0
fi