New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theme translation messages support #17
Comments
Hi @markodvornik, import { useKcLanguageTag } from "keycloakify";
const { kcLanguageTag, setKcLanguageTag } = useKcLanguageTag(); For example if language selected is slovenian you will get Now, if you don't care about type safety and don't want to implement your own translation engine you can update at runtime this object. Example: index.tsx import { kcMessages } from "keycloakify/lib/i18n/generated_kcMessages/login";
kcMessages["sk"]["my new message"] = "foo bar in slovanian";
kcMessages["en"]["my new message"] = "foo bar in english"; MyComponent.tsx import { useKcMessage } from "keycloakify";
export funct MyComponent(){
const { msgStr } =useKcMessage();
return <h1>{msgStr("my new message" as any)}</h1>;
} This will work... I hope this helps. |
Thank you for the response, much appreciated.
I didn't plan to implement my own translation engine. I am using However, I was refering to something else. How can I get a custom language (not present in the So if I understand correctly, I could define my own The second part: (2) Modify theme.properties still needs to be updated otherwise theme language is not available in the Keycloak admin. But as a workaround I can do this in a post-build process, so this is not a big issue. |
Hi,
You just need to overwrite extend kcMessages once. You could do that for example: import { kcMessages } from "keycloakify/lib/i18n/generated_kcMessages/login";
(kcMessages as any)["si"]= {
"doLogIn": "start a session in si",
"doRegister": "register in si",
//...implement only the default identifier that you use,
// if ever an identifier is not implemented you'll falbacl to english
"myCustomIdentifier": "my custom identifier in si",
"myCustomIdentifier2": "my custom identifier 2 in si"
};
Object.assign(
kcMessages["en"],
{
"myCustomIdentifier": "my custom identifier in english",
"myCustomIdentifier2": "my custom identifier 2 in english"
}
); index.tsx import "./kcMessagesExtention"; MyComponent.tsx import { useKcMessage } from "keycloakify";
export funct MyComponent(){
const { msgStr } =useKcMessage();
return <h1>{msgStr("my new message" as any)} {msgStr("doLogin")}</h1>;
}
Ok, for that the PR of asashey #18 make sense. You could do: {
"keycloakify": {
"extraThemeProperties": ["locales=en,si"]
}
} I will merge he's pr and release a new version. |
This works for updating However, partial hack is still needed: insert a translation file A solution would be some sort of CI routine that copies resource files to the |
I feel that I should reopen this because it has never been really addressed. |
My work around this is to generate the files from import * as fs from "fs";
import { kcMessages } from "./login";
Object.keys(kcMessages).map((lang) => {
let obj = kcMessages[lang];
Object.entries(obj).map(([key, value]) => {
fs.appendFile(
`./messages/messages_${lang}.properties`,
`${key}=${value}\n`,
(err) => {
if (err) throw err;
}
);
});
}); then copy the cp -r messages build_keycloak/src/main/resources/theme/demo1/login or by injecting this command in our project's scripts "keycloak": "yarn build && build-keycloak-theme && cp -r messages build_keycloak/src/main/resources/theme/demo1/login" |
thanks @ilkou, I ended up with this order of the command because if you call build-keycloak-theme and copy it afterwards it's not included in the jar (i guess)
|
Hi @loki344, It's not fully documented yet but |
There is now a proper |
I would like to add translation files to the theme.
Expected behaviour
Keycloak documentation on internationalization states that in order to support a custom language two steps are neccessary:
messages*
file inside the theme foldertheme.properties
by adding thelocales= ...
entryActual state
(1) Messages
I was investigating if translations are already supported. AFAIK the build theme script
generateKeycloakThemeResources.js
only copies theresources
folder to thetheme
folder. Themessages
folder is not mentioned in the script.To be clear what I was looking for: Keycloak expects the
messages
folder next to theresources
folder.Maybe I am missing something here, so any help regarding adding translation files would be much appreciated.
A workaround would be to add the
messages
folder to the theme by updating ajar
package once it is compiled, but that is not a permanent solution.(2) Modify theme.properties
I think this pull-request solves it: #18
The text was updated successfully, but these errors were encountered: