NewsCrawler.org

Moving translation key extraction to i18next-cli cut run time to about 19 seconds

SWCベースのi18next-cliへ移行して、翻訳キーの抽出時間を約5分の1に高速化した話
Image: zenn.dev

An engineer at Aldagram describes how extracting translation keys[1] for their web app's Japanese and English dictionary files moved from Babel[2] and babel-plugin-i18next-extract to i18next-cli[3], which parses source code with SWC[4]. Before the change the extraction took about 100 seconds; after it, about 19 seconds, roughly one fifth of the original time, measured with hyperfine over five runs. The old setup ran a full transpile on every extraction even though its output was discarded, while extraction only needs to read calls such as t('...').

To keep the existing dictionary format, primaryLanguage was set to English, so the English _one and _other plural suffixes were kept. The keySeparator and nsSeparator settings were turned off so that dots and colons stay part of keys. New keys are added with an empty default value so that the English fallback still works for Japanese, and the sort option was set to match Locize's order, which removed unrelated lines from Git diffs.

In CI, the dictionary check now runs with --ci --dry-run and fails if the dictionaries need updating. The Babel config files for extraction and the @babel/cli and babel-plugin-i18next-extract packages were removed.

Product i18next-cli i18next.com

Official high-performance CLI for i18next: extracts translation keys from code, checks languages and keeps dictionary files in sync.

Read the original zenn.dev

Sources

  • Zenn JA

    SWCベースのi18next-cliへ移行して、翻訳キーの抽出時間を約5分の1に高速化した話

    3 likes0 bookmarks0 comments

Published: First seen: Читать по-русски

Open as a page