Basic principles

This documentation explains how i18n works in the Login theme. In the Account Multi-Page theme, everything works the same as in the Login theme. You just need to replace /login/ by /account/ in the import paths.

In the Account Single-Page theme, things works differently. See relevent doc.

In the Keycloak Admin Console you can enable localisation by selecting a set of language that you wish to support:

Enabling English, French and Spanish as supported languages in a Keycloak Realm

Want to add languages not in the default set into Keycloakify? See how.

When Internationalization is enabled you will see a language dropdown select in your UIs:

If you eject some pages, you'll see in your component how the internationalization is actually implemented:

src/login/Register.tsx
export default function Register(props: RegisterProps) {
    const { i18n } = props;
    
    const { msg, msgStr, advancedMsg, advancedMsgStr } = i18n;

    return (
        //...
        <a href={url.loginUrl}>
            {msg("backToLogin")}
        </a>
        // ...
    );
}
msg("backToLogin") gets rendered as « Back to Login

If you want to see the base message translations you can navigate to the node_modules/keycloakify/src/login/i18n/messages_defaultSet/ directory:

As you can see, the translation message for the key backToLogin in English (en.ts) is:

We are <strong>sorry</strong> ...

As a result calling <p>{msg("backToLogin")}<p> returns the following JSX.Eement:

<p>
  <span data-kc-msg="backToLogin">We are <strong>sorry</strong> ...</span>
</p>

If you need to get the litteral string "We are <strong>sorry</strong> ..." instead of a JSX.Element you can use msgStr("backToLogin").

The purpose of the data-kc-msg attribute is to help you identify the i18n key of the text you want to change when inspecting the DOM.

Inspecting the DOM we can see that if we want to change the "Back to Login..." we need to change the "backToLogin" key.

Now that you get the main idea, let's see how to preview your pages in different languages:

Previewing Your Pages in Different Languages

Last updated

Was this helpful?