Internationalization and Localization Support
RubyMine supports various features that help you internationalize and localize Rails applications and plain Ruby projects. You can create or edit locale properties using intention actions right in the editor, run an inspection allowing you to find missing keys, preview localized values, etc. These capabilities are available for various project file types, including ruby scripts, HTML, ERB, and HAML files.
Following i18n conventions, RubyMine automatically loads dictionary files (YAML or Ruby) stored in the config/locales directory. If necessary, you can provide custom paths. To do this, open the Settings/Preferences dialog (Ctrl+Alt+S), go to the Project Structure page and switch to the I18n tab.
We’ll use the following project to show internationalization capabilities of the IDE:
You can repeat the steps below by checking out this application.
Create locale properties
RubyMine provides an inspection for keys that do not exist in any locale. To see this capability in action, open the app/views/static_pages/home.html.erb file and scroll down to the following code:
Place a caret at the .welcome key and press Ctrl+F1 to see a warning:
Then, press Alt+Enter, choose Create Property and press Enter:
In the invoked dialog, select a locale file and specify the property value:
You can use the button to add translations for other locales. Click OK. RubyMine will create the specified translations in the dictionary files:
You can navigate from the key called within t method to the corresponding keys in the dictionaries...
… and vice-versa.
Extract hard-coded strings
RubyMine enables you to extract hard-coded strings into locale files.
Open the app/views/static_pages/home.html.erb project file and scroll down to the following code:
Place a caret to the “Sign up now!” string, press Alt+Enter and select the I18nize hard-coded string action. Press Enter. In the Create Property dialog, specify the key and provide the desired translations:
Click OK. RubyMine will add corresponding properties to the locale files and replace the initial string with the t method called for the created key:
View locale valuesCollapse the selected fragment and create a custom folding region
RubyMine provides the ability to display localized values instead of I18n keys. To do this, place a caret at the required key and press Ctrl+. to fold it:
The preview will show the value from the system default locale. If necessary, you can use another locale to preview values by clicking Alt+Enter and selecting the Change preview locale intention action:
One more way to see all available translations for the required key is to press Ctrl+Q (Quick Documentation Lookup):