-1

I’m working on a multilingual application with the following structure:

messages/
├── en.d.json.ts   // baseline type definition
├── en.json
├── ja.json
├── zh-CN.json
└── zh-TW.json

Each file has nested keys, for example:

// en.json
{
  "navbar": {
    "navbar-mobile-menu": {
      "dashboard": "Dashboard",
      "profile": "Profile",
      "logout": "Logout"
    },
    "navbar-user-menu": {
      "login": "Login",
      "dashboard": "Dashboard",
      "profile": "Profile",
      "logout": "Logout"
    }
  }
}

I want TypeScript (and my IDE) to check at compile time that:

  1. All translation files (ja.json, zh-CN.json, zh-TW.json) have exactly the same keys as en.json.

  2. No keys are missing and no extra keys exist.

  3. Ideally, TypeScript should give me red squiggles in VSCode if a key is missing or spelled incorrectly.

How can I set this up in a clean and maintainable way?

1
  • 2
    Maybe you need some extension to work with JSON Schema (json-schema.org)? Commented Oct 1 at 18:02

2 Answers 2

0

What you are describing is a linting issue, and eslint is the most common way to handle this for typescript today.

There's a plugin that does what you want with the lint rule i18n-json/identical-keys https://github.com/godaddy/eslint-plugin-i18n-json

Sign up to request clarification or add additional context in comments.

Comments

-1

What you are looking for is i18n-ally, a VSCode extension that will help you manage your translation files with numerous options. Give it a try.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.