Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(dynamic-branding): Adds more options for overriding translations.

damenchofb3bc3c3677a
diff --git a/react/features/base/i18n/functions.tsx b/react/features/base/i18n/functions.tsx
index 2a722693b0..03b9989311 100644
--- a/react/features/base/i18n/functions.tsx
+++ b/react/features/base/i18n/functions.tsx
@@ -8,13 +8,14 @@ import i18next from './i18next';
*
* @param {string} language - The language e.g. 'en', 'fr'.
* @param {string} url - The url of the translation bundle.
+ * @param {string} ns - The namespace of the translation bundle.
* @returns {void}
*/
-export async function changeLanguageBundle(language: string, url: string) {
+export async function changeLanguageBundle(language: string, url: string, ns = 'main') {
const res = await fetch(url);
const bundle = await res.json();
- i18next.addResourceBundle(language, 'main', bundle, true, true);
+ i18next.addResourceBundle(language, ns, bundle, true, true);
}
/**
diff --git a/react/features/base/i18n/i18next.ts b/react/features/base/i18n/i18next.ts
index c9b69d2264..fc6733cfe6 100644
--- a/react/features/base/i18n/i18next.ts
+++ b/react/features/base/i18n/i18next.ts
@@ -58,6 +58,14 @@ export const DEFAULT_LANGUAGE = 'en';
*/
export const TRANSLATION_LANGUAGES_HEAD: Array<string> = [ DEFAULT_LANGUAGE ];
+/**
+ * The available/supported i18n namespaces.
+ *
+ * @public
+ * @type {Array<string>}
+ */
+export const SUPPORTED_NS = [ 'main', 'languages', 'countries', 'translation-languages' ];
+
/**
* The options to initialize i18next with.
*
@@ -81,7 +89,7 @@ const options: i18next.InitOptions = {
escapeValue: false // not needed for react as it escapes by default
},
load: 'all',
- ns: [ 'main', 'languages', 'countries', 'translation-languages' ],
+ ns: SUPPORTED_NS,
react: {
// re-render when a new resource bundle is added
// @ts-expect-error. Fixed in i18next 19.6.1.
diff --git a/react/features/base/i18n/middleware.ts b/react/features/base/i18n/middleware.ts
index 181e967751..93408e5776 100644
--- a/react/features/base/i18n/middleware.ts
+++ b/react/features/base/i18n/middleware.ts
@@ -4,7 +4,7 @@ import MiddlewareRegistry from '../redux/MiddlewareRegistry';
import { I18NEXT_INITIALIZED, LANGUAGE_CHANGED } from './actionTypes';
import { changeLanguageBundle } from './functions';
-import i18next from './i18next';
+import i18next, { SUPPORTED_NS } from './i18next';
import logger from './logger';
/**
@@ -19,9 +19,10 @@ MiddlewareRegistry.register(store => next => action => {
case LANGUAGE_CHANGED:
case SET_DYNAMIC_BRANDING_DATA: {
const { language } = i18next;
- const { labels } = action.type === SET_DYNAMIC_BRANDING_DATA
+ const data = action.type === SET_DYNAMIC_BRANDING_DATA
? action.value
: store.getState()['features/dynamic-branding'];
+ const labels = data?.labels;
if (language && labels?.[language]) {
changeLanguageBundle(language, labels[language])
@@ -30,6 +31,17 @@ MiddlewareRegistry.register(store => next => action => {
});
}
+ SUPPORTED_NS.forEach(ns => {
+ const nsLabels = data?.[`labels-${ns}`];
+
+ if (language && nsLabels?.[language]) {
+ changeLanguageBundle(language, nsLabels[language], ns)
+ .catch(err => {
+ logger.log(`Error setting dynamic language bundle for ${ns}`, err);
+ });
+ }
+ });
+
// Update transcription language, if applicable.
if (action.type === SET_DYNAMIC_BRANDING_DATA) {
const { defaultTranscriptionLanguage } = action.value;