glebm / i18n-tasks

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

Multi-line strings as translations keys are not being properly recognized by the health task #356

Open juanmanuelramallo opened 4 years ago

juanmanuelramallo commented 4 years ago

Steps to reproduce

  1. Create a call to I18n's translate like:
    I18n.t('some.very_long'\
       '.translation_key')
  2. Define the translation in your locales
    # en.yml
    en:
    some:
    very_long:
      translation_key: This is a translation with a really long key
  3. Call bundle exec i18n-tasks health

Expected

To see in the output: ✓ Good job! Every translation is in use.

Actual

Unused keys are displayed:

Unused keys (1) | i18n-tasks v0.9.31
+--------+-----------------------------------------------------------------------------------+------------------------------------------------------------------------------+
| Locale | Key                                                                               | Value                                                                        |
+--------+-----------------------------------------------------------------------------------+------------------------------------------------------------------------------+
|   en   | some.very_long.translation_key                                                    | This is a translation with a really long key                               |
+--------+-----------------------------------------------------------------------------------+------------------------------------------------------------------------------+

Why the multi-line strings

We usually encourage the line length to be 100 chars max with a RuboCop rule, then when the translation key is long or it's used in the middle of the line, we have no choice rather than splitting the string into multiple lines for better readability and complying with the code styleguide.

glebm commented 4 years ago

Is this an .rb file? Here is where the I18n.t calls are handled for .rb files, in case you want to give fixing it a go:

https://github.com/glebm/i18n-tasks/blob/0d0c16b11d0e0c7d5d7f920495dd214caacfd2b6/lib/i18n/tasks/scanners/ruby_ast_scanner.rb#L61-L88

If it's not an .rb file, fixing this will be trickier because the calls there are found with a regexp:

https://github.com/glebm/i18n-tasks/blob/0d0c16b11d0e0c7d5d7f920495dd214caacfd2b6/lib/i18n/tasks/scanners/pattern_scanner.rb#L97

juanmanuelramallo commented 4 years ago

Yes it is an .rb file, hence the RuboCop cop complains.

Thank for the heads up! I'll try to invest some time on it later this week, or maybe in the weekend.