Configuration
hias-cli uses project-level .hias/setting.json to manage translation behavior.
Create Configuration
hias settingThe config file is usually in your business project:
.hias/setting.jsonTranslation Service
Example:
{
"translationSetting": {
"locales": ["zh-CN", "en-US"],
"provider": "baidu",
"replaceOriginalFile": false,
"pruneUnusedKeys": false,
"keyStrategy": {
"maxLength": 40,
"collision": "number",
"hashLength": 6
},
"appId": "your_app_id",
"secretKey": "your_secret_key"
}
}Without credentials, the tool can still extract Chinese and generate locale files, but target languages may temporarily fall back to Chinese source text.
Language Direction
Source language is determined by the first item in the locales array; the rest are target languages.
{
"translationSetting": {
"locales": ["zh-CN", "en-US", "ja-JP"]
}
}If your source code is English and you want to generate Chinese and Japanese:
{
"translationSetting": {
"locales": ["en-US", "zh-CN", "ja-JP"]
}
}Now the source language is en-US, and target languages automatically become zh-CN and ja-JP.
Full Configuration Example
{
"translationSetting": {
"locales": ["zh-CN", "en-US"],
"outDir": ".hias/lang",
"fallbackToKey": true,
"replaceOriginalFile": false,
"provider": "tencent",
"i18nCallTemplate": "$t",
"i18nImport": "",
"extensions": [".vue", ".js", ".ts", ".jsx", ".tsx", ".json"],
"capitalizeTranslations": false,
"pruneUnusedKeys": false,
"keyStrategy": {
"maxLength": 40,
"collision": "number",
"hashLength": 6
},
"appId": "",
"secretKey": ""
}
}Field Description
| Field | Default | Description |
|---|---|---|
locales | ["zh-CN", "en-US"] | locales[0] is source language, rest are target languages |
outDir | .hias/lang | Output directory for locale files and translated copies |
fallbackToKey | true | Whether to fall back to source key when translation fails |
replaceOriginalFile | false | Whether to overwrite source files directly |
provider | tencent | Translation service: baidu or tencent |
i18nCallTemplate | $t | i18n call used when replacing source code |
i18nImport | "" | Optional import statement; default empty for auto-import projects |
extensions | [".vue", ".js", ".ts", ".jsx", ".tsx", ".json"] | Custom scan extensions; empty array means all supported types |
capitalizeTranslations | false | Whether to capitalize first letter of translations containing Latin characters |
pruneUnusedKeys | false | Whether to remove old keys not referenced by current namespace |
keyStrategy.maxLength | 40 | Maximum length for auto-generated keys |
keyStrategy.collision | number | Key collision strategy: number or hash |
keyStrategy.hashLength | 6 | Short hash length for hash collision strategy |
appId | "" | Baidu AppId or Tencent SecretId |
secretKey | "" | Baidu SecretKey or Tencent SecretKey |
Key Strategy
Default uses translated English to generate snake_case keys, with sequence numbers appended on collision:
{
"translationSetting": {
"keyStrategy": {
"maxLength": 40,
"collision": "number",
"hashLength": 6
}
}
}If you prefer stable key suffixes across multiple runs, switch to hash:
{
"translationSetting": {
"keyStrategy": {
"collision": "hash"
}
}
}Unused Key Cleanup
By default, existing keys in locale files are preserved to avoid deleting manually maintained historical translations. Enable only when you want to clean up unreferenced keys in the current namespace:
{
"translationSetting": {
"pruneUnusedKeys": true
}
}Translation Cache
Cache file location:
.hias/.translation-cache.jsonCache keys use language direction:
{
"zh-CN|en-US": {
"登录": "Login"
}
}Recommended to import via hias tci rather than manually editing the cache file.
Output Directory
Translation results are typically written to the locale module directory:
src\locale\module\demo
.hias\locale\module\demoActual paths depend on your project configuration.