RubyMine 2016.1 Help

Extracting Hard-Coded String Literals

RubyMine suggests RailsI18nInspection inspection that detects hard coded string literals in the source code, and intention action that enables you to extract them into properties files, and replace with property keys.

RubyMine recognizes string literals in the files of the various types, in particular:

  • In Ruby and Rails scripts.
  • In views.
  • In HAML files, where string literals can appear without quotes.
  • Inside tags (for example, <p>some text</p>) of HTML files.
  • In Cucumber step definitions.

To extract a hard-coded string

  1. Make sure that locale file to be used as the target, is created.
  2. Open the desired file in the editor, click the string to be extracted, press Alt+Enter, and in the list of available intention actions choose I18n string value:
    ruby_i18nExtractHardCodedString1
  3. In the Create Property dialog box, select the target locale file, and specify the new property key and value.
    ruby_extractHardCodedStringToProperty

    A key-value pair is created in the specified target locale, and the hard-coded string in question is replaced with reference:

    ruby_i18nExtractHardCodedString.png

See Also

Last modified: 21 July 2016