i18n-tasks icon indicating copy to clipboard operation
i18n-tasks copied to clipboard

Many false positives in unused

Open nurbs999 opened this issue 4 years ago • 5 comments

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

nurbs999 avatar Feb 26 '21 00:02 nurbs999

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"} |

mtancoigne avatar Mar 27 '21 08:03 mtancoigne

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

davidwessman avatar May 15 '22 18:05 davidwessman

@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:

  • t("activerecord.models.genus", count: nbr)
  • t("activerecord.models.genus.one") in combination with i18n-tasks use t("activerecord.models.genus").

davidwessman avatar May 15 '22 20:05 davidwessman

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

nurbs999 avatar May 16 '22 08:05 nurbs999

@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).

mtancoigne avatar May 16 '22 08:05 mtancoigne