This commit is contained in:
parent
cfda99f5b0
commit
f4c4e92ca1
@ -1,5 +1,6 @@
|
|||||||
import "keycloakify/tools/Object.fromEntries";
|
import "keycloakify/tools/Object.fromEntries";
|
||||||
import { assert, is } from "tsafe/assert";
|
import { assert, is } from "tsafe/assert";
|
||||||
|
import { extractLastParenthesisContent } from "keycloakify/tools/extractLastParenthesisContent";
|
||||||
import messages_defaultSet_fallbackLanguage from "../messages_defaultSet/en";
|
import messages_defaultSet_fallbackLanguage from "../messages_defaultSet/en";
|
||||||
import { fetchMessages_defaultSet } from "../messages_defaultSet";
|
import { fetchMessages_defaultSet } from "../messages_defaultSet";
|
||||||
import type { KcContext } from "../../KcContext";
|
import type { KcContext } from "../../KcContext";
|
||||||
@ -168,12 +169,10 @@ export function createGetI18n<
|
|||||||
break from_server;
|
break from_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cspell: disable-next-line
|
const lastParenthesisContent = extractLastParenthesisContent(supportedEntry.label);
|
||||||
// from "Espagnol (Español)" we want to extract "Español"
|
|
||||||
const match = supportedEntry.label.match(/[^(]+\(([^)]+)\)/);
|
|
||||||
|
|
||||||
if (match !== null) {
|
if (lastParenthesisContent !== undefined) {
|
||||||
return match[1];
|
return lastParenthesisContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return supportedEntry.label;
|
return supportedEntry.label;
|
||||||
|
43
src/tools/extractLastParenthesisContent.ts
Normal file
43
src/tools/extractLastParenthesisContent.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* "Hello (world)" => "world"
|
||||||
|
* "Hello (world) (foo)" => "foo"
|
||||||
|
* "Hello (world (foo))" => "world (foo)"
|
||||||
|
*/
|
||||||
|
export function extractLastParenthesisContent(str: string): string | undefined {
|
||||||
|
const chars: string[] = [];
|
||||||
|
|
||||||
|
for (const char of str) {
|
||||||
|
chars.push(char);
|
||||||
|
}
|
||||||
|
|
||||||
|
const extractedChars: string[] = [];
|
||||||
|
let openingCount = 0;
|
||||||
|
|
||||||
|
loop_through_char: for (let i = chars.length - 1; i >= 0; i--) {
|
||||||
|
const char = chars[i];
|
||||||
|
|
||||||
|
if (i === chars.length - 1) {
|
||||||
|
if (char !== ")") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (char) {
|
||||||
|
case ")":
|
||||||
|
openingCount++;
|
||||||
|
break;
|
||||||
|
case "(":
|
||||||
|
if (openingCount === 0) {
|
||||||
|
return extractedChars.join("");
|
||||||
|
}
|
||||||
|
openingCount--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
extractedChars.unshift(char);
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user