forked from rustfs/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate-locales.js
More file actions
63 lines (55 loc) · 1.42 KB
/
translate-locales.js
File metadata and controls
63 lines (55 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const fs = require('fs')
const path = require('path')
// 读取英文语言包
const enPath = 'i18n/locales/en-US.json'
const en = JSON.parse(fs.readFileSync(enPath, 'utf8'))
const keys = Object.keys(en)
// 语言映射配置
const languages = {
'ja-JP': {
name: '日语',
translations: {},
},
'ko-KR': {
name: '韩语',
translations: {},
},
'de-DE': {
name: '德语',
translations: {},
},
'es-ES': {
name: '西班牙语',
translations: {},
},
'pt-BR': {
name: '葡萄牙语',
translations: {},
},
'it-IT': {
name: '意大利语',
translations: {},
},
'ru-RU': {
name: '俄语',
translations: {},
},
}
console.log(`开始翻译 ${keys.length} 个键到 ${Object.keys(languages).length} 种语言...`)
// 这里需要实际的翻译逻辑
// 由于没有翻译API,我们先创建一个占位符结构
// 实际翻译需要调用翻译服务或手动翻译
Object.keys(languages).forEach(locale => {
const lang = languages[locale]
console.log(`\n处理 ${lang.name} (${locale})...`)
keys.forEach(key => {
// 暂时保持英文,实际应该调用翻译API
lang.translations[key] = en[key]
})
// 保存文件
const filePath = `i18n/locales/${locale}.json`
const content = JSON.stringify(lang.translations, null, 2) + '\n'
fs.writeFileSync(filePath, content, 'utf8')
console.log(`已保存 ${filePath}`)
})
console.log('\n翻译完成!')