RubyMine 2017.1 Help

Extracting Hard-Coded String Literals

On this page:


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.

Extracting string literals

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:
  3. In the Create Property dialog box, select the target locale file, and specify the new property key and value.

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


See Also

Last modified: 18 July 2017