Class: RuboCop::Cop::DevDoc::I18n::ReportText
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::DevDoc::I18n::ReportText
- Defined in:
- lib/rubocop/cop/dev_doc/i18n/report_text.rb
Overview
Report every user-facing text in a glib JSON-UI text prop — both hardcoded strings and already-localized ‘t(…)` calls.
## Rationale ‘DevDoc/I18n/RequireTranslation` flags only hardcoded strings; it stays silent once a value is localized. This cop is the opposite: it fires on every text value, localized or not, so you can sweep a codebase and collect the full list of user-facing strings (e.g. to seed a translation catalog or audit coverage).
It is a tooling aid, not a lint — **disabled by default** and runs at ‘info` severity. Run it during a localization pass; it is not meant for every commit.
Both the hardcoded form (‘view.p text: ’Welcome’‘) and the localized form (`view.p text: t(’home.welcome’)‘) are reported. Blank/whitespace strings and pure dynamic values (`user.name`) carry no static text and are skipped — see `DevDoc/I18n/UnverifiedTranslation` for those.
The watched method names and localizable keys are configurable via ‘WatchedMethods:` and `LocalizableKeys:`.
📋 Reported — hardcoded text
view.p text: 'Welcome'
📋 Reported — localized text
view.p text: t('home.welcome')
Constant Summary collapse
- MSG =
'Text for `%<key>s:`: review/collect this for localization.'.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
- TRANSLATION_METHODS =
%i[t translate].freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
64 65 66 67 68 69 70 71 72 |
# File 'lib/rubocop/cop/dev_doc/i18n/report_text.rb', line 64 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 |