Skip to content

Quick Start

This page demonstrates how to use hias-cli in an existing project to migrate source language text. Source code can be Chinese, English, or other non-English languages.

Installation

sh
npm i @ansstory/hias -g

Requires Node.js >= 18.

After installation, verify the command:

sh
hias -v
hias --help

Initialize Configuration

Navigate to your business project directory:

sh
# Initialize project translation settings
hias setting
# Add .hias to gitignore to prevent appId and secretKey from being committed
hias gitignore

This generates or opens the project-level config .hias/setting.json.

If you have translation service credentials, add them to the config:

json
{
  "translationSetting": {
    "locales": ["zh-CN", "en-US"],
    "outDir": ".hias/lang",
    "replaceOriginalFile": false,
    "provider": "baidu",
    "appId": "your_app_id",
    "secretKey": "your_secret_key"
  }
}

If you don't have credentials, you can still migrate the structure. The tool writes source text to locale files, and you can add translations later.

If your source code is English, adjust the locales order to translate from English to other languages:

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

Translate a Single File

sh
hias tf src\views\demo\index.vue

By default, replaceOriginalFile is false, so translated file copies and locale files are written to the output directory specified by outDir. Set to true to replace the original file directly.

Typical output:

text
翻译结果已保存到: .hias\lang\demo

You can also translate in bulk. Preview and save a report first:

sh
hias tfo src\views
# Preview mode
hias tfo src\views demo --dry-run --report .hias\reports\demo.json

For interactive confirmation:

sh
hias tfo src\views demo --interactive

Import Company Translation Tables

If your company provides Chinese-English, Japanese, or other translation tables, import them into the cache first:

sh
hias tci .\.hias\company.xlsx

Recommended format:

zh-CNen-USja-JP
登录Loginログイン
正常状态Normal Status正常状態

After importing, hias tf will prioritize existing translations from .hias/.translation-cache.json.

Check Locale Files

After translation, verify that source references and locale files are consistent:

sh
hias tcheck src --report .hias\reports\tcheck.json

It reports missing keys, unused keys, inconsistent keys across locale JSON files, and unparseable JSON files.

Released under the MIT License.