Spittal / vue-i18n-extract

Manage vue-i18n localization with static analysis
https://pixari.github.io/vue-i18n-extract/#what-is-it
MIT License
312 stars 85 forks source link

Allow key detection in brackets and parentheses #144

Closed JamesBoon closed 3 years ago

JamesBoon commented 3 years ago

If the translate function t() is used inside of brackets or parentheses, it should still be detected by vue-i18n-extract.

It would be nice if these examples would work:

const msgList = [t('some.key')];
throw new Error(t('some.other.key'));

Wouldn't it be better if the regexp uses any "not word" (\W) character as delimiter in front of the translation function?


Until then, there is a (ugly) workaround: as the vue-i18n-extract regexp requires a space in front of the translation function, the following examples already work:

const msgList = [/**/ t('some.key')];
throw new Error(/**/ t('some.other.key'));
Spittal commented 3 years ago

We're open to a PR for this functionality!

JamesBoon commented 3 years ago

Cool. I'll try it.

Looking through the sources and the tests, there is one question:
Why should ;t("FALSE POSITIVE 2"); not match? See edge-cases.js. This test was added two years ago, without any linked Issue.

If I'd add \W as delimiter, this would create a match, too. Is this change okay? I have decided against this pattern. I'll link a PR soon, then we could discuss my changes while looking at some code.

Spittal commented 3 years ago

Love the PR, I think it's great!

JamesBoon commented 3 years ago

Thank you :smile: Do you know when a new release will be available?