glebm / i18n-tasks

Manage translation and localization with static analysis, for Ruby i18n
http://glebm.github.io/i18n-tasks
MIT License
2.06k stars 260 forks source link

New unused warnings after update to v1 #443

Closed afdev82 closed 2 years ago

afdev82 commented 2 years ago

I open a new issue since I'm not sure it's related to already opened issues about false positive unused translations. Before v1 I had no warnings (v0.9.37), now I'm getting some unused translations that are used in erb files, such:

...
<main class="container-fluid mt-3" id="content">
  <div class="row">
    <div class="col">
      <h1><%= t('admin.statistics.mirror_registrations') %></h1>
    </div>
  </div>
  <div class="row pt-3 pt-md-6">
    <div class="col">
      <%= grid(@mirrors_grid, show_filters: :always, html: { class: 'table table-sm' }) do |g|
            g.column name: t('admin.statistics.name'), attribute: 'name', assoc: :mirror do |users_mirror|
              ...
            end

            g.column {
              name: t('admin.statistics.country'),
              attribute: 'country_id',
              assoc: :location,
              custom_filter: ...
            } do |users_mirror|
              ...
            end

            g.column name: t('admin.statistics.city'), attribute: 'city', assoc: :location

            g.column {
              name: "#{t('attributes.language')} <span aria-describedby=\"fn-1\">*</span>",
              attribute: 'language',
              assoc: %i[mirror mirror_slots],
              custom_filter: ...
            } do |users_mirror|
              ...
           end

            g.column name: t('attributes.created_at'), attribute: 'created_at' do |users_mirror|
              ...
            end
          end -%>
    </div>
  </div>
  ...
</main>

Some translations in the same file are found, like attributes.created_at or admin.statistics.name. Others not, like admin.statistics.country and admin.statistics.city and I don't have any idea what it could be the reason / difference. I have other examples in the file, but I took them out for brevity. The issue is happening in two files with the same structure (use of the grid method from the wice_grid gem).

I've done a git bisect, but since I'm getting errors during the scan in between, I couldn't inspect all commits. Currently I have this problem with v1.0.7 and all versions (as far as I can see) after commit d51327c.

* 152d368 2022-04-05 | Bump to v1.0.7 (HEAD -> main, tag: v1.0.7, origin/main, origin/HEAD) [Gleb Mazovetskiy]
* 9d2c825 2022-04-05 | Ignore key if scope cannot be evaluated [David Wessman]
* fed0923 2022-04-04 | Bump to v1.0.6 (tag: v1.0.6, davidwessman/main) [Gleb Mazovetskiy]
* 0a2f949 2022-03-31 | Refactors AST-matchers [David Wessman]
* 44568c8 2022-04-02 | Adds specs for multi-line erb comments [David Wessman]
* 35fcba9 2022-03-31 | Adds specs for custom_scanner [David Wessman]
* 79fe6de 2022-03-31 | ERB-Ast: Do not try to parse erb-comments [David Wessman]
* 9461e91 2022-03-26 | Bump to v1.0.5 (tag: v1.0.5) [Gleb Mazovetskiy]
* c2c257d 2022-03-26 | Handle multiline ERB comments [Gleb Mazovetskiy]
* eb97672 2022-03-25 | Bump to v1.0.4 (tag: v1.0.4) [Gleb Mazovetskiy]
* ef007fb 2022-03-25 | Fixes parsing of ERB comments without a space (refs/bisect/skip-ef007fb5a4d35bf0a3b1e11e79e458c39ba0a854) [Gleb Mazovetskiy]
* 6a2e995 2022-03-25 | Make interpolations variable regex configurable (refs/bisect/skip-6a2e9958f6f4b17528460cfd050bcd6528f1f9f9) [Gleb Mazovetskiy]
* 33ec754 2022-03-24 | Bump to v1.0.3 (tag: v1.0.3, refs/bisect/skip-33ec754b35f5e5ddbf63b04e97ffcc1af0e86c59) [Gleb Mazovetskiy]
* 487a0f3 2022-03-24 | Occurrence: Changes inspect format (refs/bisect/bad) [David Wessman]
* 3575d8f 2022-03-24 | ErbAst: Handles inline block (refs/bisect/skip-3575d8f65dfa530074d4ecbc0de897b73b65246d) [David Wessman]
* dbbcd3a 2022-03-24 | Bump to v1.0.2 (tag: v1.0.2, refs/bisect/skip-dbbcd3abe659c379b7832dba892c896ca6133652) [Gleb Mazovetskiy]
* 0fe8ee5 2022-03-24 | Occurence: Adds keys to inspect string (refs/bisect/skip-0fe8ee58c8bbd2f3c5ec18b6547492eac72267cd) [David Wessman]
* e642f96 2022-03-24 | ErbAst: Handles blocks (refs/bisect/skip-e642f9683c6442f2e85b286cbd47ad41c1a93086) [David Wessman]
* 9c0c354 2022-03-24 | Bump to v1.0.1 (tag: v1.0.1, refs/bisect/skip-9c0c354e959ce27fb4de3d6c47490efc7e554bec) [Gleb Mazovetskiy]
* 8e2541b 2022-03-23 | Changes better_html import (refs/bisect/skip-8e2541b8e5cae1a57197436915f4e9f7197d8b99) [David Wessman]
* 4378481 2022-03-22 | Bump to v1.0.0 (tag: v1.0.0, refs/bisect/skip-4378481ed51512aadef3706cbc36887e1e795fe9) [Gleb Mazovetskiy]
* 7d50880 2022-03-22 | Log #StandWithUkraine to stderr (refs/bisect/skip-7d50880f4e650debdcff9a1493fff799c1eb4d8e) [Gleb Mazovetskiy]
* d9b30e9 2022-03-22 | README.md: Stand with Ukraine (refs/bisect/skip-d9b30e91c3d96b7be4a8542cf9676ac3a9f4a08f) [Gleb Mazovetskiy]
* f90f53d 2022-03-22 | Changelog for v1.0.0 (refs/bisect/skip-f90f53ddfc66484c6c4072558c71873cdd7373f3) [Gleb Mazovetskiy]
* 20f67ea 2022-03-22 | Repair emojis after dump of yaml (refs/bisect/skip-20f67ea5f8b13cf592cef12b00b0f1ac3494ff56) [Liberatys]
* 8cdef9c 2022-03-22 | Add Ruby deprecation events to CHANGES (refs/bisect/skip-8cdef9cf14df7e7db7b0350bc6f09d7ce4700b98) [Aleksandrs Ļedovskis]
* d7ae6e6 2022-02-13 | Adds AST scanner for ERB-files (refs/bisect/skip-d7ae6e6e9158ae7581c1e36079eb32117d4aa77f) [David Wessman]
* d51327c 2022-01-20 | Ensured Aliased values work (#415) (refs/bisect/good-d51327cb48870f984303da55fe1a0605cf0e70d3) [Colin Bruce]
* 3a886ce 2022-01-19 | Include Ruby 3.1 in github workflow test matrix (refs/bisect/good-3a886ce14279b30137c14621b0b56ff144d97cc1) [Colin Bruce]
* 933ce62 2021-12-26 | Improve tests workflow [Gleb Mazovetskiy]
* 779ab32 2021-12-26 | Bump to v0.9.37 (tag: v0.9.37, refs/bisect/good-779ab325e8835b6f3cf58c8213e1426278007961) [Gleb Mazovetskiy]

Let me know if I can help further. Thank you for your help!

davidwessman commented 2 years ago

Seems like good examples to add to the ERB-test suite! 🙂

afdev82 commented 2 years ago

I found that the syntax used was not valid, I had to change from

g.column {
  name: t('admin.statistics.country'),
  attribute: 'country_id',
  assoc: :location,
  custom_filter: ...
} do |users_mirror|
  ...
end

to

g.column name: t('admin.statistics.country'),
                     attribute: 'country_id',
                     assoc: :location,
                     custom_filter: ... do |users_mirror|
              ...
            end

And this has solved also the issue with the unused translations! Sorry for the noise.

davidwessman commented 2 years ago

Ah, that makes sense!