glebm / i18n-tasks

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

Many false positives in unused #373

Open nurbs999 opened 3 years ago

nurbs999 commented 3 years ago

I have quiet fresh Rails project and I get many false positives when I run bundle exec i18n-tasks unused e.g. I have <h1><%= t('welcome message h1') %></h1> in my application.html.erb and I get this key as unused for all languages. It's the same for many other translations I use in my views.

I use ruby-2.7.2, rails-6.1.0, i18n-tasks-0.9.33

mtancoigne commented 3 years ago

Hi !

I use version 0.9.34 but can tell it was already present on previous versions.

I got this yaml:

fr:
  activerecord:
    models:
      genus:
        one: Genre
        other: Genres

and a file with:

# auto-generated models an attributes for i18n
# i18n-tasks-use t('activerecord.models.genus')

Which works as expected.

But once I target one or other key, the whole fr.activerecord.model.genus gets flagged as unused:

<%= t('activerecord.models.genus.one') %>
+--------+--------------------------------------------+-------------------------------------+
| Locale | Key                                        | Value                               |
+--------+--------------------------------------------+-------------------------------------+
|   en   | activerecord.models.genus                  | {"one"=>"Genus", "other"=>"Genera"} |
|   fr   | activerecord.models.genus                  | {"one"=>"Genre", "other"=>"Genres"} |
davidwessman commented 2 years ago

@nurbs999 Can you please explain how your translation files looks to work with a key like welcome message h1?

davidwessman commented 2 years ago

@mtancoigne Hello! I tried to recreate this problem, and it seems to be a limitation with pluralization - if you have a pluralized translation you will have to use one of:

nurbs999 commented 2 years ago

I don't have the project running anymore. I will try to reproduce it on my current setup, which is ruby-3.0.2, rails-6.1.4

mtancoigne commented 2 years ago

@davidwessman Thanks for your reply, that's what I do currently. I'll stick with this : it's not really an issue unless I want the model name in JS scripts (as the i18n lib I use don't have the same format for plural forms).