This commit is contained in:
@@ -32,14 +32,15 @@ type PlatformLanguageProviderProps = {
|
||||
|
||||
const STORAGE_KEY = "govoplan.language";
|
||||
const PRIMARY_LANGUAGE = "en";
|
||||
const REFERENCE_LANGUAGE = "de";
|
||||
const I18N_MESSAGE_SEPARATOR = "::";
|
||||
const TRANSLATABLE_ATTRIBUTES = ["aria-label", "alt", "placeholder", "title"];
|
||||
const SKIP_TRANSLATION_SELECTOR = "script, style, code, pre, textarea, [data-i18n-skip]";
|
||||
const textNodeOriginals = new WeakMap<Text, string>();
|
||||
|
||||
export const DEFAULT_AVAILABLE_LANGUAGES: PlatformLanguage[] = [
|
||||
{ code: "en", label: "i18n:govoplan-core.english.649df08a", nativeLabel: "i18n:govoplan-core.language_native_english" },
|
||||
{ code: "de", label: "i18n:govoplan-core.german.da91388c", nativeLabel: "i18n:govoplan-core.language_native_german" }];
|
||||
{ code: "de", label: "i18n:govoplan-core.german.da91388c", nativeLabel: "i18n:govoplan-core.language_native_german" },
|
||||
{ code: "en", label: "i18n:govoplan-core.english.649df08a", nativeLabel: "i18n:govoplan-core.language_native_english" }];
|
||||
|
||||
|
||||
export const DEFAULT_TRANSLATIONS: PlatformTranslations = {
|
||||
@@ -186,13 +187,17 @@ function languagesForCodes(languages: PlatformLanguage[], codes?: string[] | nul
|
||||
|
||||
function preferredLanguage(languages: PlatformLanguage[], preferred?: string | null): string {
|
||||
const codes = new Set(languages.map((item) => item.code));
|
||||
const requested = normalizeLanguageCode(preferred ?? storedLanguage() ?? browserLanguage());
|
||||
if (codes.has(requested)) return requested;
|
||||
const primary = primaryLanguageCode(requested);
|
||||
const primaryMatch = languages.find((item) => primaryLanguageCode(item.code) === primary);
|
||||
if (primaryMatch) return primaryMatch.code;
|
||||
const requestedValue = preferred ?? storedLanguage() ?? browserLanguage();
|
||||
if (requestedValue) {
|
||||
const requested = normalizeLanguageCode(requestedValue);
|
||||
if (codes.has(requested)) return requested;
|
||||
const primary = primaryLanguageCode(requested);
|
||||
const primaryMatch = languages.find((item) => primaryLanguageCode(item.code) === primary);
|
||||
if (primaryMatch) return primaryMatch.code;
|
||||
}
|
||||
if (codes.has(REFERENCE_LANGUAGE)) return REFERENCE_LANGUAGE;
|
||||
if (codes.has(PRIMARY_LANGUAGE)) return PRIMARY_LANGUAGE;
|
||||
return languages[0]?.code ?? PRIMARY_LANGUAGE;
|
||||
return languages[0]?.code ?? REFERENCE_LANGUAGE;
|
||||
}
|
||||
|
||||
function primaryLanguageCode(value: string): string {
|
||||
|
||||
Reference in New Issue
Block a user