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.
Extracting string literals
To extract a hardcoded string
- Make sure that the locale file to be used as the target, is created.
- 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 :
- 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 hardcoded string in question is replaced with reference: