Fix syncronization with non react pages

This commit is contained in:
Joseph Garrone
2021-03-05 19:50:08 +01:00
parent a69bee8726
commit 06ab2ab82e
7 changed files with 47 additions and 51 deletions

View File

@ -90,11 +90,6 @@ export function generateKeycloakThemeResources(
"destDirPath": tmpDirPath
});
transformCodebase({
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "common"),
"destDirPath": pathJoin(tmpDirPath, "..", "common")
});
transformCodebase({
"srcDirPath": pathJoin(tmpDirPath, "keycloak", "login", "resources"),
"destDirPath": pathJoin(themeDirPath, "resources")
@ -106,10 +101,7 @@ export function generateKeycloakThemeResources(
fs.writeFileSync(
pathJoin(themeDirPath, "theme.properties"),
Buffer.from([
`import=common/${themeName}`,
"locales=ca,cs,de,en,es,fr,it,ja,lt,nl,no,pl,pt-BR,ru,sk,sv,tr,zh-CN"
].join("\n"), "utf8")
Buffer.from("parent=keycloak", "utf8")
);
}

View File

@ -44,7 +44,7 @@ export const Template = memo((props: TemplateProps) => {
displayInfoNode = null
} = props;
console.log("Rendering this page with react using keycloak-react-theming");
useEffect(()=> { console.log("Rendering this page with react using keycloak-react-theming") },[]);
const { t } = useKcTranslation();
@ -53,7 +53,7 @@ export const Template = memo((props: TemplateProps) => {
const { kcLanguageTag, setKcLanguageTag } = useKcLanguageTag();
const onChangeLanguageClickFactory = useCallbackFactory(
([languageTag]: [KcLanguageTag]) =>
([languageTag]: [KcLanguageTag]) =>
setKcLanguageTag(languageTag)
);
@ -138,9 +138,9 @@ export const Template = memo((props: TemplateProps) => {
<ul>
{
locale.supported.map(
({ languageTag }) =>
({ languageTag, url }) =>
<li className="kc-dropdown-item">
<a href="#" onClick={onChangeLanguageClickFactory(languageTag)}>
<a href={url} onClick={onChangeLanguageClickFactory(languageTag)}>
{getKcLanguageTagLabel(languageTag)}
</a>

View File

@ -55,12 +55,16 @@ export function getBestMatchAmongKcLanguageTag(
const iso2LanguageLike = languageLike.split("-")[0].toLowerCase();
const language = availableLanguages.find(language =>
const kcLanguageTag = availableLanguages.find(language =>
language.toLowerCase().includes(iso2LanguageLike) ||
getKcLanguageTagLabel(language).toLocaleLowerCase() === languageLike.toLocaleLowerCase()
);
if (language === undefined && languageLike !== navigator.language) {
if (kcLanguageTag !== undefined) {
return kcLanguageTag;
}
if (languageLike !== navigator.language) {
return getBestMatchAmongKcLanguageTag(navigator.language);
}

View File

@ -9,5 +9,5 @@ export const { useKcLanguageTag } = createUseGlobalState(
kcContext?.locale?.["current" as never] ??
navigator.language
),
{ "persistance": "cookies" }
{ "persistance": "cookie" }
);

View File

@ -27,7 +27,7 @@ export declare namespace KcContext {
/** Undefined if !realm.internationalizationEnabled */
locale?: {
supported: {
//url: string;
url: string;
languageTag: KcLanguageTag;
/** Is determined by languageTag. Ex: languageTag === "en" => label === "English"
* or getLanguageLabel(languageTag) === label