RubyMine 2018.3 Help

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:

https://bitbucket.org/rubyminedoc/sample_rails_app/

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:

<h1><%= t('.welcome') %></h1>

Place a caret at the .welcome key and press Ctrl+F1 to see a warning:

missing key warning

Then, press Alt+Enter, choose Create Property and press Enter:

create locale property

In the invoked dialog, select a locale file and specify the property value:

create property dialog

You can use the add button to add translations for other locales. Click OK. RubyMine will create the specified translations in the dictionary files:

yaml localization key

You can navigate from the key called within t method to the corresponding keys in the dictionaries...

navigate to keys

… 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:

<%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %>

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:

create property dialog

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:

<%= link_to t('.signup'), signup_path, class: "btn btn-lg btn-primary" %>

View locale values

Collapse 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+Period to fold it:

preview locale property

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:

change preview locale

One more way to see all available translations for the required key is to press Ctrl+Q (Quick Documentation Lookup):

quick documentation for locale keys
Last modified: 6 December 2018