Skip to content
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

Fix overrides #4273

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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