Class: RuboCop::Cop::DevDoc::I18n::UnverifiedTranslation
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::DevDoc::I18n::UnverifiedTranslation
- Defined in:
- lib/rubocop/cop/dev_doc/i18n/unverified_translation.rb
Overview
Warn when a glib text prop is set from a non-literal value that isn’t a ‘t(…)` call — it may be an unlocalized string.
## Rationale ‘DevDoc/I18n/RequireTranslation` only catches string literals written at the call site. A value passed through a variable or method (`label: label_text`) escapes it — the literal could be one hop away. This cop flags those values so a human can confirm they resolve through I18n.
It can’t tell a stashed literal from genuinely dynamic data (‘user.name`) or a translation reached via a variable, so it’s a review aid, not a clean lint: it’s **disabled by default** and runs at ‘info` severity. Run it during a localization pass, not on every commit. Values that are obviously translated (`t(…)`, `translate`, `I18n.t`) are excluded; literals are left to `RequireTranslation`.
⚠️ Can't be verified — confirm it's localized
view.fields_text label: label_text
view.p text: user.name
✔️ Obviously localized — not flagged
view.p text: t('home.welcome')
Constant Summary collapse
- MSG =
'Possibly unlocalized: `%<key>s:` is set from a non-literal. ' \ 'Use `t(...)` if this is user-facing text.'.freeze
- DYNAMIC_TYPES =
%i[lvar ivar send csend].freeze
- TRANSLATION_METHODS =
%i[t translate].freeze
- DEFAULT_WATCHED_METHODS =
%w[ h1 h2 h3 h4 h5 p label markdown fields_text fields_number fields_select fields_password fields_textarea fields_check fields_checkGroup fields_chipGroup fields_timeZone fields_radioGroup fields_date fields_datetime ].freeze
- DEFAULT_LOCALIZABLE_KEYS =
%w[ title subtitle subsubtitle label placeholder text ].freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
59 60 61 62 63 64 65 66 67 |
# File 'lib/rubocop/cop/dev_doc/i18n/unverified_translation.rb', line 59 def on_send(node) return unless watched_methods.include?(node.method_name.to_s) node.arguments.each do |arg| next unless arg.hash_type? arg.pairs.each { |pair| check_pair(pair) } end end |