Keycloakify
HomeGitHubStorybookAlternative to keycloak-js
v11
  • Documentation
  • Release Notes & Upgrade Instructions
  • FAQ
v11
  • Quick Start
  • CSS Customization
  • Testing your Theme
    • Outside of Keycloak
    • Inside of Keycloak
  • Deploying Your Theme
  • Integrating Keycloakify in your Codebase
    • Vite
    • Create-React-App / Webpack
    • yarn/npm/pnpm/bun Workspaces
    • Turborepo
    • Nx
    • Angular Workspace
  • Common Use Case Examples
    • Using a Component Library
    • Custom Fonts
    • Changing the background image
    • Adding your Logo
    • Using Tailwind
    • Dark Mode Persistence
  • Features
    • Internationalization and Translations
      • Basic principles
      • Previewing Your Pages in Different Languages
      • Adding New Translation Messages or Changing the Default Ones
      • Adding Support for Extra Languages
    • Theme Variants
    • Environment Variables
    • Styling a Custom Page Not Included in Base Keycloak
    • Integrating an Existing Theme into Your Keycloakify Project
    • Compiler Options
      • --project
      • keycloakVersionTargets
      • environmentVariables
      • themeName
      • startKeycloakOptions
      • themeVersion
      • accountThemeImplementation
      • postBuild
      • XDG_CACHE_HOME
      • kcContextExclusionsFtl
      • keycloakifyBuildDirPath
      • groupId
      • artifactId
      • Webpack specific options
        • projectBuildDirPath
        • staticDirPathInProjectBuildDirPath
        • publicDirPath
  • Page-Specific Guides
    • Registration Page
    • Terms and Conditions Page
  • Theme types
    • Differences Between Login Themes and Other Types of Themes
    • Account Theme
      • Single-Page
      • Multi-Page
    • Email Theme
    • Admin Theme
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Features
  2. Internationalization and Translations

Basic principles

Last updated 4 months ago

Was this helpful?

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

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

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

You shouldn't rely on the language select to let your users select their language.

Infact, I encourage you to hide or remove it.

What you should do instead is, when redirecting your user from your application to your Keycloak login page, add an extra query param to let Keycloak know in what language the page should be rendered.

The parameter to add is ?ui_locales=fr (Example if we want the UI to be in French).

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>
        // ...
    );
}
src/login/pages/Register.svelte
<script lang="ts">
  // ...
  const props: RegisterProps = $props();
  const { i18n } = props;
  const { msg, msgStr, advancedMsg } = $i18n;
</script>

<a href={url.loginUrl}>{@render msg('backToLogin')()}</a>
src/login/pages/register/register.component.html
<a
  [href]="url.loginUrl"
  [innerHTML]="i18n.msgStr('backToLogin') | kcSanitize: 'html'"
></a>

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

Don't edit this file directly, it's just for seeing what are the default set of i18n messages.

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").

As a result calling <p>{@render msg("backToLogin")}</p> returns the following snippet:

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

As a result calling i18n.msgStr('errorTitleHtml') return the string "We are <strong>sorry</strong> ..." and you need to pass it sanitarized as [innerHTML] so that "sorry" be redered in bold:

    <p
        [innerHTML]="i18n.msgStr('errorTitleHtml') | kcSanitize: 'html'"
    ></p>

What will actually be rendered in the DOM will be:

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

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.

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

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

See for more info on how to provide this parameter. (You can do the same if you use keycloak-js or NextAuth)

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

See how
oidc-spa documentation
eject some pages
Previewing Your Pages in Different Languages
See relevent doc
Enabling English, French and Spanish as supported languages in a Keycloak Realm
msg("backToLogin") gets rendered as « Back to Login
Inspecting the DOM we can see that if we want to change the "Back to Login..." we need to change the "backToLogin" key.