mxmvshnvsk / i18n-unused

The static analyze tool for finding, marking and removing unused and missing i18n translations in your JavaScript project
MIT License
127 stars 21 forks source link

Error when trying to use sync task #20

Open loettz opened 2 years ago

loettz commented 2 years ago

Hi 👋 thank you for the great package 🙏 mark-unused and remove-unused worked well for me, but I have an issue using the sync task (see screenshot). localesPath and srcPath is set in the config file (no other settings). node version is 16.13.1 Do you have any suggestions for me on how to get the sync task to work or why it fails? Thank you in advance 🙂

Bildschirmfoto 2022-06-24 um 16 18 32

cornelius-illi commented 2 years ago

Hi @loettz and @mxmvshnvsk,

I think the issue comes done to some pre-condition to be met/ assumption about the structure of a project when using i18n-unused.

Assume the following configuration of your i18n-unused.config.js: module.exports = { localesPath: 'src/locales', srcPath: 'src', }; The script works as intended, e.g. if called like this on two files in the same locale directory: npx i18n-unused sync common.de.json common.en.json

However, if the files are organized with sub-directories the script will fail, e.g. with a structure like this. /src/locales/de/common.json /src/locales/en/common.json

I feel that this structure is quite common and do support to resolve this issue by being able to resolve folder structures. Maybe take some inspiration from the config of https://github.com/i18next/i18next-scanner resource: { loadPath: 'i18n/{{lng}}/{{ns}}.json', savePath: 'i18n/{{lng}}/{{ns}}.json', jsonIndent: 2, lineEnding: '\n' },

Thanks a lot! Best, Cornelius