Localization

Learn how to localize strings in the UIs.

Keycloak supports localized text throughout all user interfaces.

Prerequisites

Localizing messages in a theme

Text in the templates is loaded from message bundles. When a theme extends another theme, the child theme inherits all messages from the parent’s message bundle. You can override individual messages by adding <THEME TYPE>/messages/messages_en.properties to your theme.

For example, to replace Username on the login form with Your Username for the mytheme, create the file themes/mytheme/login/messages/messages_en.properties with the following content:

usernameOrEmail=Your Username

Within a message, values like {0} and {1} are replaced with arguments when the message is used. For example {0} in Log in to {0} is replaced with the name of the realm.

Texts of these message bundles can be overwritten by realm-specific values, which are manageable by the UI and API.

Adding a language to a theme

Procedure
  1. Create the file <THEME TYPE>/messages/messages_<LOCALE>.properties in the directory of your theme.

  2. Add this file to the locales property in <THEME TYPE>/theme.properties. For a language to be available to users in a realm, the login, account, and email theme types must support the language, so you need to add your language for those theme types.

    For example, to add Norwegian translations to the mytheme theme, create the file themes/mytheme/login/messages/messages_no.properties with the following content:

    usernameOrEmail=Brukernavn
    password=Passord

    If you omit a translation for messages, those messages appear in English.

  3. Edit themes/mytheme/login/theme.properties and add:

    locales=en,no
  4. Make the same changes to the account and email theme types. To make these changes, create themes/mytheme/account/messages/messages_no.properties and themes/mytheme/email/messages/messages_no.properties. If you leave these files empty, English messages appear.

  5. Copy themes/mytheme/login/theme.properties to themes/mytheme/account/theme.properties and themes/mytheme/email/theme.properties.

  6. Add a translation for the language selector by adding a message to the English translation. Add the following to themes/mytheme/account/messages/messages_en.properties and themes/mytheme/login/messages/messages_en.properties:

    locale_no=Norsk

By default, message properties files should be encoded using UTF-8. Keycloak falls back to ISO-8859-1 handling if it cannot read the contents as UTF-8. Unicode characters can be escaped as described in Java’s documentation for PropertyResourceBundle. Previous versions of Keycloak had support for specifying the encoding in the first line with a comment such as # encoding: UTF-8, which is no longer supported.

Additional resources

Overriding localized text for an entire realm

You also have the option to declare translations that take effect for an entire realm. You specify key/value pairs in the realm settings. Any key specified in this way overrides the key/value pairs deployed with a theme.

In most cases, using realm overrides is not the recommended way to achieve localization in Keycloak. Consider carefully if you want every theme in your realm to use a key/value pair declared as a realm override.
Procedure to add a realm override
  1. Log into the Admin Console.

  2. Select your realm.

  3. Click Realm Settings from the menu.

  4. Click on the Localization tab.

  5. Click on the Realm overrides subtab.

  6. Select a language from the option list.

  7. Click Add translation.

  8. Create a key/value pair from the modal dialog.

Notice another subtab called Effective message bundles. This subtab provides a tool to query key/value pairs for a combination of theme, language, and theme type. You can use this tool to test and make sure your realm overrides took effect.

On this page