ember-intl-analyzer icon indicating copy to clipboard operation
ember-intl-analyzer copied to clipboard

Add option to log dynamic translation lookups (in HBS files)

Open robinborst95 opened this issue 2 years ago • 0 comments

This PR adds the option to detect dynamic translation lookups, as suggested in https://github.com/simplabs/ember-intl-analyzer/issues/9. This is still a work in progress (e.g. it needs more tests), but it can be tested manually already. For now this only detects them in HBS files, but with some changes I think it's doable for JS files as well (in another PR though).

Note that this PR builds on top of https://github.com/simplabs/ember-intl-analyzer/pull/483, as I made changes there that made it easy to detect dynamic parts in a template.

@Turbo87, is this what you had in mind (if anything) in terms of logging? I was also thinking of trying to map unused translations to the dynamic translations to find a match as a suggestion for the whitelist. To illustrate what I mean by that: if you have the following in a template:

{{t (concat "prefix." this.dynamicKey ".value")}}

and an actual translation:

prefix:
  concrete-type:
    value: Some value

then this PR logs out:

prefix.{{this.dynamicKey}}.value

This is something we can turn into a regex:

/^prefix\..*\.value$/

and provide as a suggestion for whitelisting the unused translation.

robinborst95 avatar May 26 '22 15:05 robinborst95