Skip to content

Configuration

hias-cli uses project-level .hias/setting.json to manage translation behavior.

Create Configuration

sh
hias setting

The config file is usually in your business project:

text
.hias/setting.json

Translation Service

Example:

json
{
  "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.

json
{
  "translationSetting": {
    "locales": ["zh-CN", "en-US", "ja-JP"]
  }
}

If your source code is English and you want to generate Chinese and Japanese:

json
{
  "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

json
{
  "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

FieldDefaultDescription
locales["zh-CN", "en-US"]locales[0] is source language, rest are target languages
outDir.hias/langOutput directory for locale files and translated copies
fallbackToKeytrueWhether to fall back to source key when translation fails
replaceOriginalFilefalseWhether to overwrite source files directly
providertencentTranslation service: baidu or tencent
i18nCallTemplate$ti18n 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
capitalizeTranslationsfalseWhether to capitalize first letter of translations containing Latin characters
pruneUnusedKeysfalseWhether to remove old keys not referenced by current namespace
keyStrategy.maxLength40Maximum length for auto-generated keys
keyStrategy.collisionnumberKey collision strategy: number or hash
keyStrategy.hashLength6Short 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:

json
{
  "translationSetting": {
    "keyStrategy": {
      "maxLength": 40,
      "collision": "number",
      "hashLength": 6
    }
  }
}

If you prefer stable key suffixes across multiple runs, switch to hash:

json
{
  "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:

json
{
  "translationSetting": {
    "pruneUnusedKeys": true
  }
}

Translation Cache

Cache file location:

text
.hias/.translation-cache.json

Cache keys use language direction:

json
{
  "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:

text
src\locale\module\demo
.hias\locale\module\demo

Actual paths depend on your project configuration.

Released under the MIT License.