Skip to content

Commit

Permalink
Fix overrides (#4273)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Jun 28, 2023
1 parent 0788197 commit d8d9126
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions scripts/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {appConfig, getUserInterfaceLanguage} from 'appConfig';

export const i18n = gettextjs();

if (window.language != null && window.translations != null) {
if (window.translations != null) {
const language = window.translations['']['language'];

i18n.setMessages(
Expand Down Expand Up @@ -66,7 +66,7 @@ export const gettext = (

let translated = i18n.gettext(text);

Object.keys(params ?? {}).forEach((param) => {
Object.keys(params).forEach((param) => {
translated = translated.replace(new RegExp(`{{\\s*${param}\\s*}}`, 'g'), params[param]);
});

Expand Down
20 changes: 12 additions & 8 deletions scripts/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ export const DEFAULT_ENGLISH_TRANSLATIONS = {'': {'language': 'en', 'plural-form
const language = getUserInterfaceLanguage();
const filename = `/languages/${language}.json?nocache=${Date.now()}`;

function requestListener() {
const translations = JSON.parse(this.responseText);

if (translations[''] == null || translations['']['language'] == null || translations['']['plural-forms'] == null) {
throw new Error(`Language metadata not found in "${filename}"`);
}

function applyTranslations(translations) {
const langOverride = appConfig.langOverride ?? {};

if (langOverride[language] != null) {
Expand All @@ -20,8 +14,18 @@ function requestListener() {
window.translations = translations;
}

function requestListener() {
const translations = JSON.parse(this.responseText);

if (translations[''] == null || translations['']['language'] == null || translations['']['plural-forms'] == null) {
throw new Error(`Language metadata not found in "${filename}"`);
}

applyTranslations(translations);
}

if (language === 'en') {
window.translations = DEFAULT_ENGLISH_TRANSLATIONS;
applyTranslations(DEFAULT_ENGLISH_TRANSLATIONS);
} else {
const req = new XMLHttpRequest();

Expand Down

0 comments on commit d8d9126

Please sign in to comment.