7

I'm wondering if anyone knows of a good way / tool / package to checking for unused translations

I've seen it for rails, like i18n-tasks but nothing for react

I'm currently using react-i18next, but it could be anything that looks through your translation file

Thanks so much in advance

Kaelyn
  • 171
  • 1
  • 6
  • There are [multiple extraction tools](https://react.i18next.com/guides/extracting-translations#2-using-an-extraction-tool) available. Based on these, you can easily write a small tool that will warn you when it finds an existing translation that is no longer found in the extracted keys (if the tools are not already doing that automatically) – Bergi Jul 22 '20 at 21:58

4 Answers4

7

List unused translations keys

There is i18-unused library which prints list of all unused keys for all json files.

npm install --save-dev i18n-unused

To make it work make sure you add config i18n-unused.config.js in root directory with path to your locales (localesPath) and all js files (srcPath).

//i18n-unused.config.js
module.exports = {
  localesPath: 'src/locales',
  srcPath: 'src',
};

Then run:

i18n-unused display-unused
Aga
  • 1,019
  • 1
  • 11
  • 16
  • 1
    I followed your steps but I got this error: "i18n-unused : The term 'i18n-unused' is not recognized as the name of a cmdlet" on a windows machine – Nemus Feb 27 '23 at 09:28
3

I used i18next-scanner. It can remove unused translations (see removeUnusedKeys options).

Zakhar
  • 2,143
  • 2
  • 15
  • 15
1

if you‘re using i18next combined with locize, there‘s a dedicated i18next plugin to find unused translations: https://docs.locize.com/guides-tips-and-tricks/unused-translations

adrai
  • 2,495
  • 1
  • 15
  • 18
0

I use react-18next frequently, and I don't believe there is a tool to check for this. Although, is it necessary? The performance losses are probably negligable.

Nicholas Harder
  • 1,496
  • 10
  • 15
  • Thanks for your response. It’s more so cause I want these keys to be translated into 20 different languages and it would become pretty costly. I’ve been reverse checking it manually but it would be nice to automate / clean up in general – Kaelyn Jul 22 '20 at 21:34