Dark theme | Light theme

October 16, 2020

Enforce Encoding i18n Property Files In Keycloak Themes

Keycloak allows internationalization messages in themes. We can specify property files with messages for a specific locale. The fallback locale is always en, so we need at least the file To use the messages from the property files we use the msg function in our Freemarker templates. We specify the message key as argument to this function and the corresponding value will be shown to the user. This function is added by Keycloak and reads the property files, finds the key and returns the value. Keycloak uses as default encoding for reading the property files ISO-8859-1. This gives issues when we use non-compliant characters in our property file, like letters with accents. We can force Keycloak to use anonther encoding by adding an extra line to our property files at the top with the encoding we want to be used. The line starts with a #, so it is a comment, followed by the text encoding: and the encoding we want, e.g. UTF-8.

In the following example we set the encoding to UTF-8 as first line in the property file, and we must make sure the file is also saved with the same encoding:

# encoding: UTF-8 

In the following Freemaker template we use the msg function to get the key doSave:

<button name="submitAction" value="Save">${msg("doSave")}<button>

Written with Keycloak 11.0.2.