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

i18n-tasks does not recognize absolute keys #215

Closed AdrienGiboire closed 7 years ago

AdrienGiboire commented 7 years ago

I rarely use absolute keys so I don't know if this behaviour is recent but it's been two consecutive days now that I notice this issue.

I have a file: app/views/pro/products/_form.html.haml In which I have this: = t('pro.products.build.form.asap') Running i18n-tasks missing produces:

✓ Well done! No translations are missing.

Changing by this: = t('.pro.products.build.form.asap') Running i18n-tasks missing produces:

+--------+------------------------------------------------+-------------------------------------------+
| Locale | Key                                            | Value in other locales or source          |
+--------+------------------------------------------------+-------------------------------------------+
|  all   | pro.products.form.pro.products.build.form.asap | app/views/pro/products/_form.html.haml:62 |
+--------+------------------------------------------------+-------------------------------------------+

There is no asap key whatever the scope in my translation file. And it's the third key I've noticed being ignored by i18n-tasks.

Just to assure you the asap key does not exist, I ran the following: = t('.asap') Running i18n-tasks missing produces:

+--------+------------------------+-------------------------------------------+
| Locale | Key                    | Value in other locales or source          |
+--------+------------------------+-------------------------------------------+
|  all   | pro.products.form.asap | app/views/pro/products/_form.html.haml:62 |
+--------+------------------------+-------------------------------------------+

Am I missing something?

glebm commented 7 years ago

This is strange. What does your config/i18n-tasks.yml look like? What is your i18n-tasks version?

AdrienGiboire commented 7 years ago

v0.9.5

config/i18n-tasks.yml:

# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks

# The "main" locale.
base_locale: en-US
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
# locales: ['fr-FR']
locales: ['en-US']
## Reporting locale, default: en. Available: en, ru.
# internal_locale: en

# Read and write translations.
data:
  ## Translations are read from the file system. Supported format: YAML, JSON.
  ## Provide a custom adapter:
  # adapter: I18n::Tasks::Data::FileSystem

  # Locale files or `File.find` patterns where translations are read from:
  read:
    ## Default:
    - config/locales/%{locale}.yml
    ## More files:
    # - config/locales/**/*.%{locale}.yml
    ## Another gem:
    # - "<%= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml"

  # Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
  # `i18n-tasks normalize -p` will force move the keys according to these rules
  write:
    ## For example, write devise and simple form keys to their respective files:
    # - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
    ## Catch-all default:
    # - config/locales/%{locale}.yml

  ## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
  # router: convervative_router

  yaml:
    write:
      # do not wrap lines at 80 characters
      line_width: -1

  ## Pretty-print JSON:
  # json:
  #   write:
  #     indent: '  '
  #     space: ' '
  #     object_nl: "\n"
  #     array_nl: "\n"

# Find translate calls
search:
  ## Paths or `File.find` patterns to search in:
  paths:
   - app/

  ## Root directories for relative keys resolution.
  relative_roots:
    - app/views
    - app/controllers
    - app/helpers
    - app/mailers
    - app/services

  ## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
  ##   %w(*.jpg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less *.yml *.json)
  exclude:
    - app/assets/images
    - app/assets/fonts

  ## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
  ## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
  # include: ["*.rb", "*.html.slim"]

  ## Default scanner finds t() and I18n.t() calls.
  # scanner: I18n::Tasks::Scanners::PatternWithScopeScanner

## Google Translate
# translation:
#   # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
#   api_key: "AbC-dEf5"

## Do not consider these keys missing:
ignore_missing:
  - 'admin.*'
  - 'application_helper.errors.title' # because depending on routes
  - 'application_mailer.mailer.default_from'
  - 'pro.products.build.*' # because they are handle by wicked
  - 'creators.products.load_product.not_in_segments_error' # because of before filter
  - '{fill,group,roundrect,stroke}' # generic JS spinner translation
# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
# - '{devise,simple_form}.*'

## Consider these keys used:
ignore_unused:
  - 'mailer.default_from'
  - 'activemodel.errors.*'
  - 'activerecord.{attributes,errors,models,state_machines}.*'
  - 'countries.*'
  - 'currency.*'
  - 'date.*'
  - 'datetime.*'
  - '{devise,will_paginate}.*'
  - 'enumerize.*'
  - 'errors.messages.*'
  - 'locations.*'
  - 'number.*'
  - 'pro.scorecard.*' # because they are dynamically computed
  - 'pro.products.build.form.*' # because they are handle by wicked
  - 'pro.stores.form.*' # because they are handle by application / simple_form
  - 'simple_form.{true,false}'
  - 'simple_form.{yes,no}'
  - 'simple_form.{hints,error_notification,labels,placeholders,required}.*'
  - 'support.array.*'
  - 'time.*'
  - 'creators.products.show.not_in_segments_error' # because of before filter
  - 'pro.yt_videos.card.products_count'
  - 'pro.yt_videos.card.reviewing_html'
  - 'pro.yt_videos_helper.products_count'
  - 'pro.yt_videos_helper.reviewing_html'

## Exclude these keys from the `i18n-tasks eq-base' report:
# ignore_eq_base:
#   all:
#     - common.ok
#   fr,es:
#     - common.brand

## Ignore these keys completely:
# ignore:
#  - kaminari.*
glebm commented 7 years ago

This:

= t('pro.products.build.form.asap')

Is ignored because of:

ignore_unused:
- 'pro.products.build.form.*' 

In general, I recommend against using ignore_unused where you can avoid it. E.g. for forms you can add / i18n-tasks-use t('<key here>') for every field instead of ignoring them all (but update i18n-tasks to v0.9.6 if you do because v0.9.5 has buggy i18n-tasks-use).

AdrienGiboire commented 7 years ago

oh shit… sorry… thanks :)