---
title: "How to detect missing translation keys during compile time (Typescript)"
description: "This article explains how you can detect missing translation keys when compiling your app."
canonical: "https://www.codeandweb.com/babeledit/knowledgebase/detecting-missing-translation-keys-at-compiletime"
product: "babeledit"
source: "html"
---

# How to detect missing translation keys during compile time (Typescript)

This tip is for anyone who wants to translate their TypeScript-based applications, such as when using React, Angular (ngx-translate), or Vue.js.

You know how missing translation keys can be a real pain? They can cause issues in your app, and you only find out about them when you test the whole thing. And the error only pops up when you actually try to use that key. Luckily, there's an easy way to fix this if you're using TypeScript.

Suppose you have the following translation file: **en.json**:

en.json

```json
{
  "greeting": "Hello",
  "farewell": "Goodbye",
  "thanks": "Thank you"
}
```

You can now import the language file into your application:

TranslationKeys.ts

```typescript
import * as enJson from './en.json';
export type TranslationKeys = keyof typeof enJson;
```

To import the .json files, you have to modify your **tsconfig.json**:

tsconfig.json

```json
{
  "compilerOptions": {
    "resolveJsonModule": true,
    // ... other compiler options
  },
  // ... other settings
}
```

Now, you can use the TranslationKeys type in your application like this:

main.ts~

```typescript
import type {TranslationKeys} from "./TranslationKeys";

const translate = (key: TranslationKeys) => console.log(key); // just a dummy function

translate("greeting"); // ok
translate("missingkey"); // type-error
```

Update the `translate(key: TranslationKeys)` function, as a wrapper for the 'real' translation function.

Nice bonus: You get Intellisense auto-completion for your prompts in Visual Studio Code and PhpStorm:

![Auto completion for translation keys in Visual-Studio Code and PhpStorm](https://www.codeandweb.com/static/2f781a14730d7f3e2253eaefb70f45dd/21cde/intellisense-completion-for-translation-keys%402x.png)

The limitation is that it doesn't work with nested JSON files.

You have to convert the file

```json
{
    "main": {
        "sub": "a sub key"
    }
}
```

to this, to make it work:

```json
{
    "main.sub": "a sub key"
}
```

The great thing is that BabelEdit does this for you. After importing the keys,

After importing your project, simply open the settings and change the **Format** to **JSON with namespaces in keys, tree view**.

![Converting JSON file formats from nested to flat keys.](https://www.codeandweb.com/static/48de2123c8a978a800a8b324b539c321/2be44/convert-json-files-using-babeledit%402x.png)

BabelEdit also keeps the files consistent for you so that it's sufficient to only use your primary language in the import.

To check all languages you can use:

TranslationKeys.ts

```typescript
import * as enJson from './en.json';
import * as deJson from './de.json';
export type TranslationKeys = keyof typeof enJson & keyof typeof deJson;
```

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "TechArticle",
  "headline": "How to detect missing translation keys during compile time (Typescript)"
}
```
