Skip to content

Cache Import

cache-import imports your company's existing translation tables into .hitf/.translation-cache.json for reuse in subsequent translations.

Command

sh
hitf cache-import .\.hitf\company.xlsx

Or use the short command:

sh
hitf tci .\.hitf\company.xlsx

.xlsx is recommended. The first row contains language codes, and each subsequent row is one text entry.

zh-CNen-USja-JP
登录Loginログイン
正常状态Normal Status正常状態
请输入用户名Please Enter Usernameユーザー名を入力してください

This format is friendly for product, operations, and translation teams, and makes it easy to add language columns later.

Supported Formats

FormatDescription
.xlsxRecommended format, suitable for company maintenance
.xlsm / .xlsCompatible for import
.tsv / .txtTab-separated plain text tables

Multilingual Write Method

The import tool writes each target language to the translation cache:

json
{
  "zh-CN|en-US": {
    "登录": "Login"
  },
  "zh-CN|ja-JP": {
    "登录": "ログイン"
  }
}

When translating from zh-CN to en-US or ja-JP, the cache is prioritized.

Common Options

Specify source language:

sh
hitf tci .\.hitf\company.xlsx -s zh-CN

Specify worksheet:

sh
hitf tci .\.hitf\company.xlsx -S Sheet1

Overwrite existing cache:

sh
hitf tci .\.hitf\company.xlsx -o
OptionShortDescription
-s, --source <locale>-sSource locale column, default uses zh-CN when present
-S, --sheet <name>-SXLSX worksheet name, default uses the first sheet
-o, --overwrite-oOverwrite existing cached translations when values differ

When to Use

Import your company's glossary before batch translation, especially in these scenarios:

  1. Short words like login, menu, button, and status need consistent capitalization.
  2. Your company already has multilingual assets and you don't want to call machine translation again.
  3. Languages like Japanese and Korean need human translation for natural expression.
  4. Multiple projects share the same business terminology.

Apply Cache to Locale Files (cache-apply)

cache-apply (short command tca) writes translation results to locale JSON files under outDir.

How it works:

  1. Uses the source-locale JSON (key → source text) as the lookup table
  2. Cache hit → uses the cached translation directly
  3. Cache miss → automatically calls the translation API, results are cached
  4. JSON structure and all other key-value pairs are preserved; source files are never touched
sh
hitf tca

Use cases:

  1. replaceOriginalFile: true mode: Source files have been rewritten to $t() calls, re-running tf / tfo can no longer extract Chinese text. cache-apply can re-translate from locale files.
  2. Translation service switch: Changed translation API (e.g., from Baidu to OpenAI), need to re-translate uncached entries.
  3. Post-network recovery: Previously failed translations due to network issues, now network is back, re-translate failed entries.
  4. Post dictionary import: After importing new dictionary via cache-import, refresh locale files.

Common usage:

sh
# Process a single namespace only (a subdirectory under outDir)
hitf tca views

# Specify the project key when outDir is an object
hitf tca -p admin

Execution flow:

  1. Reads source-locale JSON (e.g., zh-CN.json) as key → source text lookup table
  2. For each key, checks translation cache:
    • Hit → uses cached translation
    • Miss → calls translation API, caches the result
  3. Updates target-locale JSON (e.g., en-US.json)
  4. Re-running is idempotent — nothing is written when locale files are already up to date

Released under the MIT License.