Module: RuboCop::Cop::DevDoc::I18n::LocalizableProps
- Included in:
- ReportText, RequireTranslation
- Defined in:
- lib/rubocop/cop/dev_doc/i18n/localizable_props.rb
Overview
Shared traversal for the glib JSON-UI localization cops
(RequireTranslation, ReportText).
It locates user-facing text values on watched glib component calls and
hands each (key, value_node) to the including cop's
#inspect_localizable, which decides whether to report. Three call
shapes are covered:
* hash prop: `view.p text: '...'`
* nested hash prop: `view.icon tooltip: { text: '...' }`
* jbuilder positional: `json.title '...'`
Nested hashes (and hashes inside arrays, e.g. select options) are walked to any depth, so a localizable key is found wherever it sits.
The watched method names and localizable keys are configurable via
WatchedMethods: and LocalizableKeys:.
Constant Summary collapse
- DEFAULT_WATCHED_METHODS =
%w[ h1 h2 h3 h4 h5 h6 p label markdown html button switch chip progressCircle shareButton fields_text fields_number fields_select fields_password fields_textarea fields_check fields_checkGroup fields_chipGroup fields_timeZone fields_radioGroup fields_date fields_datetime fields_upload dialogs_alert dialogs_notification snackbars_alert snackbars_select banners_alert banners_select ].freeze
- DEFAULT_LOCALIZABLE_KEYS =
%w[ title subtitle subsubtitle label placeholder text message description uploadText leftText rightText onLabel ].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
42 43 44 45 46 47 48 |
# File 'lib/rubocop/cop/dev_doc/i18n/localizable_props.rb', line 42 def on_send(node) if watched_methods.include?(node.method_name.to_s) node.arguments.each { |arg| each_localizable(arg) } end check_jbuilder_positional(node) end |