본문으로 건너뛰기

chki18n번역 파일이 서로 맞는지 검사합니다

모든 i18n JSON 구조를 25가지 항목으로 검사합니다. 커맨드라인과 CI, 직접 호출하는 코드 어디에서든 JavaScript, Dart, Python으로 실행합니다.

chki18n

실제 모습

번역 파일이 있는 폴더와 기준 언어를 지정하면 됩니다.

bash
npx chki18n ./locales --target en
bash
dart pub global activate chki18n
chki18n ./locales --target en
bash
pip install chki18n
chki18n ./locales --target en
text
  Path     ./locales
  Target   en
  Locales  en, ko
  Layout   single, 1 group, 10 keys

 ko ──────────────────────────────────────────────────────────────────────── 1 error · 1 warning

  ERROR  NO_KEY (1)
         The key exists in the target language but is missing here.
    attr.folder  en: "Folder"

  WARN   NOT_TRANSLATED_VALUE (1)
         The value is identical to the target language, so the translation may be incomplete.
    desc.no-str  en: "12345"

 Summary ───────────────────────────────────────────────────────────────────────────────────────

  Compared 10 keys across 2 locales in 1 group. (3ms)
  1 error · 1 warning
  Clean: en

  FAIL  1 error must be fixed before this passes.

오류 수준의 이슈가 있으면 종료 코드 1로 끝나므로 CI 작업이 여기서 실패합니다. 어느 패키지를 설치하든 이 리포트는 열 위치까지 똑같습니다.

같은 검사를 코드에서 실행하면 텍스트 대신 객체를 받습니다.

javascript
import { checkTranslationFiles } from 'chki18n';

const result = await checkTranslationFiles('./locales', { target: 'en' });

result.success; // false
result.summary; // { error: 1, warn: 1, info: 0, total: 2, byCode: {…}, byLocale: {…} }
result.issues[0];
// {
//   code: 'NO_KEY',
//   level: 'error',
//   locale: 'ko',
//   key: 'attr.folder',
//   group: '',
//   targetValue: 'Folder',
//   file: '/project/locales/ko.json',
//   message: 'The key exists in the target language but is missing here.'
// }
dart
import 'package:chki18n/chki18n.dart';

final result = await checkTranslationFiles(
  path: './locales',
  options: const Chki18nOptions(target: 'en'),
);

result.success; // false
result.summary.error; // 1
result.issues.first;
// Chki18nIssue(
//   code: Chki18nCheckCode.noKey,
//   level: Chki18nLevel.error,
//   locale: 'ko',
//   key: 'attr.folder',
//   group: '',
//   targetValue: 'Folder',
//   file: '/project/locales/ko.json',
//   message: 'The key exists in the target language but is missing here.',
// )
python
from chki18n import Options, check_translation_files

result = check_translation_files("./locales", Options(target="en"))

result.success  # False
result.summary.error  # 1
result.issues[0]
# Issue(
#     code="NO_KEY",
#     level="error",
#     locale="ko",
#     key="attr.folder",
#     group="",
#     target_value="Folder",
#     file="/project/locales/ko.json",
#     message="The key exists in the target language but is missing here.",
# )

설치는 시작하기 한 페이지면 충분합니다. 각 검사가 무엇을 잡아내는지는 검사 항목에, 모든 옵션은 옵션에 정리되어 있습니다.

Released under the MIT License