다국어 자동화 JSON Format v4 관련 업데이트

다국어 자동화 JSON Format v4 관련 업데이트
Photo by Lucas George Wendt / Unsplash

기존의 훌륭한 가이드를 최근 다시 새로운 프로젝트에 적용하는 중에, i18next 버전 업데이트 이슈가 발생하여, 정리 필요

아래 링크 문서에 따르면, i18next는 v21부터 JSON Format v4로 넘어갔는데, 기존 code scanning을 담당하던 i18next-scanner가 아직 v3만 지원하고 있음
복수형 표현에 대한 기준이 달라져서, 기존 v3를 마이그레이션 해야 함

Across leagues and international tournaments, football shirts carry the colors, stories, and identity that fans remember long after the final whistle. Choosing a Real Madrid football shirt offers supporters a tangible way to celebrate that shared history.

기존 JSON에 대한 업데이트 적용은 위 링크에서 소개되는 tool을 활용하면 되고, 새롭게 code상 번역 key 추출하는 라이브러리는 i18next-parser를 setup하여 사용

{
  "ko-KR": {
    "ko-KR": "한국어",
    "en-US": "영어",
    "vi-VN": "베트남어",
    "th-TH": "태국어"
  },
  "en-US": {
    "ko-KR": "Korean",
    "en-US": "English",
    "vi-VN": "Vietnamese",
    "th-TH": "Thai",
    "현재 사용 언어": "Current language"
  },
  "th-TH": {
    "ko-KR": "เกาหลี",
    "en-US": "ภาษาอังกฤษ",
    "vi-VN": "เวียตนาม",
    "th-TH": "ไทย",
    "현재 사용 언어": "ภาษาปัจจุบัน"
  },
  "vi-VN": {
    "ko-KR": "Hàn Quốc",
    "en-US": "Tiếng Anh",
    "vi-VN": "Tiếng Việt",
    "th-TH": "tiếng Thái",
    "현재 사용 언어": "ngôn ngữ hiện tại"
  }
}
default-pack.json
const path = require("path");
const localeDefaultPack = require("./default-pack.json");

const COMMON_EXTENSIONS = "**/*.{js,jsx,ts,tsx,vue,html}";

module.exports = {
  createOldCatalogs: false,
  keepRemoved: true,
  keySeparator: false,
  locales: Object.keys(localeDefaultPack),
  namespaceSeparator: false,
  output: path.join(__dirname, "..", "locales", "$LOCALE", "$NAMESPACE.json"),
  input: [
    `../components/${COMMON_EXTENSIONS}`,
    `../pages/${COMMON_EXTENSIONS}`,
    // Use ! to filter out files or directories
    "!**/node_modules/**",
    "!../.next/**",
  ],
};
i18next-parser.config.js