mxmvshnvsk/i18n-unused

translationKey on multiline does not work

Closed this issue ยท 3 comments

Here are the package I'm using

  • i18n-unused@0.13.0
  • eslint@8.4.10
  • vue@3.2.47
  • vue-i18n@9.2.2

Issue

When I'm running the following command

i18m-unused display-unused

There a lot of translations keys which aren't unused.

Example

Here a examples of patter that do not work

this.$t(
  'app.user.confirmation.delete',
  { user: 'MyUser' },
);

this.$t('app.user.confirmation.delete',
  { user: 'MyUser' });

this.$t('app.user.confirmation.delete',
  { user: 'MyUser' },
);

Here are example that work :
(Unfortunately, I cannot place all my translation on a single line , because, I use eslint which force me to not have a ligne with length greater then 100.)

this.$t('app.user.confirmation.delete', { user: 'MyUser' });

We have the same issue, that our linting rules forbid long lines.

So I dove a bit into the code and found the default matching regex: /(?:[$ .](_|t|tc))\(.*?\)/gi
Screenshot 2023-10-24 at 11 00 58

After adding whitespace [\n\r\s] to the regex, it matches your other translations as well ๐Ÿ‘ : /(?:[$ .](_|t|tc))\(([\n\r\s]|.)*?\)/gi
Screenshot 2023-10-24 at 11 01 07


The only thing you have to do is add the regex to your i18n-unused.config.js, so that it looks like this:

module.exports = {
  ...
  translationKeyMatcher: /(?:[$ .](_|t|tc))\(([\n\r\s]|.)*?\)/gi,
};

Hope this helps ๐Ÿ‘

Thanks also for this project @mxmvshnvsk, I can create a PR for this as well to add the whitespace for the default regex. Wdyt?

Hi. Sounds great =)

Hi. Sounds great =)

Done ๐Ÿ‘