diff --git a/apps/meteor/client/lib/utils/applyCustomTranslations.ts b/apps/meteor/client/lib/utils/applyCustomTranslations.ts index f629ed1aaace..aa9f81ecf0ae 100644 --- a/apps/meteor/client/lib/utils/applyCustomTranslations.ts +++ b/apps/meteor/client/lib/utils/applyCustomTranslations.ts @@ -1,28 +1,7 @@ -import { settings } from '../../../app/settings/client'; import { i18n } from '../../../app/utils/lib/i18n'; -const parseToJSON = (customTranslations: string) => { - try { - return JSON.parse(customTranslations); - } catch (e) { - return false; - } -}; - -export const applyCustomTranslations = (): void => { - const customTranslations: string | undefined = settings.get('Custom_Translations'); - - if (!customTranslations || !parseToJSON(customTranslations)) { - return; - } - - try { - const parsedCustomTranslations: Record = JSON.parse(customTranslations); - - for (const [lang, translations] of Object.entries(parsedCustomTranslations)) { - i18n.addResourceBundle(lang, 'core', translations); - } - } catch (e) { - console.error('Invalid setting Custom_Translations', e); +export const applyCustomTranslations = (parsedCustomTranslations: Record): void => { + for (const [lang, translations] of Object.entries(parsedCustomTranslations)) { + i18n.addResourceBundle(lang, 'core', translations); } }; diff --git a/apps/meteor/client/providers/TranslationProvider.tsx b/apps/meteor/client/providers/TranslationProvider.tsx index fdddb9ec5349..bc4e6a6c8ca4 100644 --- a/apps/meteor/client/providers/TranslationProvider.tsx +++ b/apps/meteor/client/providers/TranslationProvider.tsx @@ -69,6 +69,7 @@ const useI18next = (lng: string): typeof i18next => { } if (lngs && parsedCustomTranslations) { + applyCustomTranslations(parsedCustomTranslations); for (const language of Array.isArray(lngs) ? lngs : [lngs]) { if (!parsedCustomTranslations[language]) { continue; @@ -286,7 +287,7 @@ const TranslationProviderInner = ({ language: i18n.language, languages: availableLanguages, loadLanguage: async (language: string): Promise => { - i18n.changeLanguage(language).then(() => applyCustomTranslations()); + i18n.changeLanguage(language); }, translate: Object.assign(addSprinfToI18n(t), { has: ((key, options) => key && i18n.exists(key, options)) as TranslationContextValue['translate']['has'], diff --git a/apps/meteor/client/stories/contexts/TranslationContextMock.tsx b/apps/meteor/client/stories/contexts/TranslationContextMock.tsx index ac98cd15cd89..31f46711daf4 100644 --- a/apps/meteor/client/stories/contexts/TranslationContextMock.tsx +++ b/apps/meteor/client/stories/contexts/TranslationContextMock.tsx @@ -14,7 +14,7 @@ const TranslationContextMock = ({ children }: TranslationContextMockProps): Reac const value = useMemo>(() => { i18next.init({ fallbackLng: 'en', - defaultNS: 'project', + defaultNS: 'core', resources: { en: { project: require('../../../packages/rocketchat-i18n/i18n/en.i18n.json'),