Skip to content

The "it" gem support

Gleb Mazovetskiy edited this page Mar 25, 2022 · 7 revisions

While there is no plugin for the it gem yet, you can support it like this for now:

# lib/i18n_tasks_it.rb
# The "it" gem support for i18n-tasks
I18n::Tasks.add_scanner(
  '::I18n::Tasks::Scanners::RubyAstScanner',
  receiver_messages: [nil, AST::Node.new(:const, [nil, :It])].product(%i[it]),
  only: %w[*.rb]
)
I18n::Tasks.add_scanner(
  '::I18n::Tasks::Scanners::ErbAstScanner',
  receiver_messages: [nil, AST::Node.new(:const, [nil, :It])].product(%i[it]),
  only: %w[*.erb]
)
I18n::Tasks.add_scanner(
  '::I18n::Tasks::Scanners::PatternWithScopeScanner',
  translate_call: /(?<=^|[^\w'\-.]|[^\w'\-]It\.|It\.)it/,
  exclude: %w[*.erb *.rb]
)
I18n::Tasks::Interpolations.variable_regex = /%{[^}:]+[}:]/.freeze
# config/i18n-tasks.yml.erb
<% require './lib/i18n_tasks_it' %>

This requires i18n-tasks v1.0.4+.