RubyMine 2024.1 Help

Internationalization and localization

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, and so on. 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 dialog Ctrl+Alt+S, go to the Project Structure page and switch to the I18n tab.

We’ll use the sample Rails application 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, do the following:

  1. Open the app/views/static_pages/home.html.erb file and scroll down to the following code:

    <h1><%= t('.welcome') %></h1>
  2. Place a caret at the .welcome key and press Ctrl+F1 to see a warning:

    missing key warning
  3. Then, press Alt+Enter, choose Create Property and press Enter:

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

    create property dialog

    Use the add button to add translations for other locales. Then, click OK to create the specified translations in the dictionary files:

    yaml localization key
  5. 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. To try this capabiltity using the sample Rails application, do the following:

  1. 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" %>
  2. Place a caret to the “Sign up now!” string, press Alt+Enter and select the I18nize hard-coded string action. Press Enter.

  3. 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

RubyMine provides the ability to display localized values instead of I18n keys. To try this capabiltity using the sample Rails application, do the following:

  1. Place a caret at the required key and press Ctrl+. to fold it:

    preview locale property

    The preview will show the value from the system default locale.

  2. To use another locale to preview values, press Alt+Enter and select Change preview locale:

    change preview locale
  3. 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: 28 March 2024