{"action":"created","issue":{"url":"https://api.github.com/repos/glebm/i18n-tasks/issues/191","repository_url":"https://api.github.com/repos/glebm/i18n-tasks","labels_url":"https://api.github.com/repos/glebm/i18n-tasks/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/glebm/i18n-tasks/issues/191/comments","events_url":"https://api.github.com/repos/glebm/i18n-tasks/issues/191/events","html_url":"https://github.com/glebm/i18n-tasks/issues/191","id":138667427,"number":191,"title":"`i18n-tasks missing` resulting in false positive when `I18n.t` is called from a helper","user":{"login":"lucascaton","id":86755,"avatar_url":"https://avatars.githubusercontent.com/u/86755?v=3","gravatar_id":"","url":"https://api.github.com/users/lucascaton","html_url":"https://github.com/lucascaton","followers_url":"https://api.github.com/users/lucascaton/followers","following_url":"https://api.github.com/users/lucascaton/following{/other_user}","gists_url":"https://api.github.com/users/lucascaton/gists{/gist_id}","starred_url":"https://api.github.com/users/lucascaton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucascaton/subscriptions","organizations_url":"https://api.github.com/users/lucascaton/orgs","repos_url":"https://api.github.com/users/lucascaton/repos","events_url":"https://api.github.com/users/lucascaton/events{/privacy}","received_events_url":"https://api.github.com/users/lucascaton/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-05T10:28:32Z","updated_at":"2016-03-05T13:07:48Z","closed_at":null,"body":"Hi there, I think have found a bug :-)\r\n\r\nWith a simple Rails app:\r\n\r\n```ruby\r\n# app/helpers/pages_helper.rb\r\nmodule PagesHelper\r\n  def locale_test\r\n    t '.something'\r\n  end\r\nend\r\n```\r\n\r\n```erb\r\n<%# app/views/pages/index.html.erb %>\r\n<h1><%= locale_test %></h1>\r\n```\r\n\r\n```yaml\r\n# config/locales/en.yml\r\nen:\r\n  pages:\r\n    index:\r\n      something: 'Something!!!'\r\n```\r\n\r\nIt works:\r\n![image](https://cloud.githubusercontent.com/assets/86755/13547118/48fd1d94-e310-11e5-84a6-d06e93727463.png)\r\n\r\nBut:\r\n\r\n```\r\n$ i18n-tasks missing\r\n\r\nMissing translations (1) | i18n-tasks v0.9.4\r\n+--------+------------------------------------+----------------------------------+\r\n| Locale | Key                                | Value in other locales or source |\r\n+--------+------------------------------------+----------------------------------+\r\n|  all   | pages_helper.locale_test.something | app/helpers/pages_helper.rb:3    |\r\n+--------+------------------------------------+----------------------------------+\r\n```"},"comment":{"url":"https://api.github.com/repos/glebm/i18n-tasks/issues/comments/192640317","html_url":"https://github.com/glebm/i18n-tasks/issues/191#issuecomment-192640317","issue_url":"https://api.github.com/repos/glebm/i18n-tasks/issues/191","id":192640317,"user":{"login":"glebm","id":216339,"avatar_url":"https://avatars.githubusercontent.com/u/216339?v=3","gravatar_id":"","url":"https://api.github.com/users/glebm","html_url":"https://github.com/glebm","followers_url":"https://api.github.com/users/glebm/followers","following_url":"https://api.github.com/users/glebm/following{/other_user}","gists_url":"https://api.github.com/users/glebm/gists{/gist_id}","starred_url":"https://api.github.com/users/glebm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glebm/subscriptions","organizations_url":"https://api.github.com/users/glebm/orgs","repos_url":"https://api.github.com/users/glebm/repos","events_url":"https://api.github.com/users/glebm/events{/privacy}","received_events_url":"https://api.github.com/users/glebm/received_events","type":"User","site_admin":false},"created_at":"2016-03-05T13:07:48Z","updated_at":"2016-03-05T13:07:48Z","body":"Unfortunately, this is not a bug but a limitation of i18n-tasks. The static analysis always resolves relative keys based on the filename (+ the enclosing method name in case of .rb files).\r\n\r\nThere are ways to work around this. First, make i18n-tasks ignore this key:\r\n\r\n```yaml\r\nignore_missing:\r\n- pages_helper.locale_test.something\r\n```\r\n\r\nThen, there are two options:\r\n\r\nA) Add `i18n-tasks-use` hints at all call sites, e.g.:\r\n    \r\n```html.erb\r\n<% # i18n-tasks-use t('pages.index.something') %>\r\n<h1><%= locale_test %></h1>\r\n```\r\n\r\nThis is a good option if there are only a few call sites.\r\n\r\nB) Add a custom scanner like this:\r\n\r\n```ruby\r\n# config/i18n-tasks/something_scanner.rb\r\nrequire 'i18n/tasks/scanners/file_scanner'\r\nclass SomethingScanner < I18n::Tasks::Scanners::FileScanner\r\n  include I18n::Tasks::Scanners::RelativeKeys\r\n  include I18n::Tasks::Scanners::OccurrenceFromPosition\r\n\r\n  # @return [Array<[absolute key, Results::Occurrence]>]\r\n  def scan_file(path)\r\n    text = read_file(path)\r\n    text.scan(/^\\s*<%=\\s*locale_test\\b/).map do |_match|\r\n      occurrence = occurrence_from_position(\r\n          path, text, Regexp.last_match.offset(0).first)\r\n      [absolute_key('.something', path), occurrence]\r\n    end\r\n  end\r\nend\r\nI18n::Tasks.add_scanner 'SomethingScanner', only: %w(*.html.erb)\r\n```\r\n\r\n```yaml\r\n# config/i18n-tasks.yml.erb\r\n<% require './config/i18n-tasks/something_scanne.rb' %>\r\n```\r\n\r\nThis is a better option if there are many call sites."}}