Custom locale messages do not apply

Hello guys,

I try to add a custom locale support to a Keycloak installation and the texts do not load.
I can see that the locale is chosen (I look at the locale select and see it selected) but the texts that are loaded are the default fallback English ones.

This is my theme folder structure:

image

This is the contents of messages_he.properties:

image

This is theme.properties:

image

What am I doing wrong?
Please help

Hi, before you investigate any further, can you try the following :

  • set the theme for Keycloak’s default theme (not sure which one you have been using);
  • set “he” as your default locale for the realm your are testing;
  • expire your realm cache;
  • open a new Incognito/Private window in your browser and check if the text for your Login screen was changed - you should also have an option to switch to another locale;
  • if it remains in English, try restarting your server and see if it works.

If you are using RH SSO, I believe locales do not work the same way.

Hi, lvillaca I tried all of your suggestions but unfortunately it did not work, including restarting the server.

I tried adding the French language to the supported languages and it worked fine. It seems like only the custom language I’ve added is not working.
Even overrides I added for French in my theme worked.

There is no issue with the Hebrew script, I know that from adding the “locale_he” message to the messages_en.properties file with a value in Hebrew.

Do you have any more suggestions, please?

Hi @gabguy, I was about to tell you to try using unicode instead of actual hebrew letters, but it seems like those are working fine for you.

Did you provide messages_he.properties only for your “labos” theme? It seems you are extending not only login part of the theme, but also email and account - you may want to check this post. You can also try adding the message bundle it to keycloak / base theme login dir structure and check if it makes any difference. Good luck there!

Thank you very much for your responses.
Unfortunately, I’ve tried adding the messages_he files to the base theme which my theme extends and it still did not work.
I also added the file to each part of the theme login / account / email and enabled my theme for all three in KC admin settings, but that also did not solve the issue.

Might be a bug with KC?

You mentioned about a test you performed validating some Hebrew letters:

There is no issue with the Hebrew script, I know that from adding the “locale_he” message to the messages_en.properties file with a value in Hebrew.

I wonder if there is any character that could be causing an issue with freemarker.

Can you try getting your English values to messages_he.properties - maybe you can keep the Hebrew value you tested - and see Keycloak recognizes this he file? Then you could maybe migrate the remaining values in blocks, and find a culprit char (if there is one).

Either that or the other way around - replace the full messages_en.properties oil with all your Hebrew values and check if that works.

Thanks again.

Well I tried putting my Hebrew strings in the messages_en file and it works well.
So it just seems like the messages_he file is not loading for some reason and there is no issue with the strings (or chars) themselves.

Any further ideas?

try removing the locales line from the theme.properties file and see if that makes a difference

I have a minimal theme under https://github.com/zonaut/keycloak-extensions/tree/master/theme-minimal/src/main/resources and don’t have that locales property

Thanks, unfortunately this did not work.

Hello,
I’m having the exact same issue - did you manage to resolve it, or find a way around it?

@shunit Unfortunately still no solution for this issue

I believe newer Java runtimes convert he to iw for OS compatibility. Can you try changing your file to messages_iw.properties?

1 Like

@ben.overcash - Thank you! Using “iw” instead of “he” works!

Update
Yes, indeed. You cannot name the files messages_he.properties. Any other name works.
I named mine messages_heb.properties and it works well

I fixed this by changing the Keycloak service module.

My scenario: I am sending the kc_locale as a URL parameter in the login page URL.

Added the following code into getLocaleCookieSelection(RealmModel realm, HttpHeaders httpHeaders) method in org.keycloak.locale.DefaultLocaleSelectorProvider class

        String cookie_locale = session.getContext().getUri().getQueryParameters().get("kc_locale").get(0);
        if(cookie_locale != null && cookie_locale.length() == 2) {
            return findLocale(realm, cookie_locale);
        }

Fix on KC version 16.1.0

A small code change to handle some exceptions during logout and redirections.

        try {
            String cookie_locale = session.getContext().getUri().getQueryParameters().get("kc_locale").get(0);
            if (cookie_locale != null && cookie_locale.length() == 2) {
                LocaleUpdaterProvider localeUpdater = session.getProvider(LocaleUpdaterProvider.class);
                localeUpdater.updateLocaleCookie(cookie_locale);

                return findLocale(realm, cookie_locale);
            }
        } catch(NullPointerException e){
            //e.printStackTrace();
        }

In my case, I solved the issue by changing Admin Console Theme from keycloak.v2 to keycloak.
PS: I used Keycloak version 19.0.1

Hi @gabguy
Actually I’ve tried with “iw” and with “heb” too and not working :smirk:
You can help please??

Thanks,
Sharon