Skip to content

Commit

Permalink
Fix applyCustomTranslations not being called
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Sep 13, 2023
1 parent 9b58e80 commit 4422857
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
27 changes: 3 additions & 24 deletions apps/meteor/client/lib/utils/applyCustomTranslations.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown> = 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<string, unknown>): void => {
for (const [lang, translations] of Object.entries(parsedCustomTranslations)) {
i18n.addResourceBundle(lang, 'core', translations);
}
};
3 changes: 2 additions & 1 deletion apps/meteor/client/providers/TranslationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -286,7 +287,7 @@ const TranslationProviderInner = ({
language: i18n.language,
languages: availableLanguages,
loadLanguage: async (language: string): Promise<void> => {
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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TranslationContextMock = ({ children }: TranslationContextMockProps): Reac
const value = useMemo<ContextType<typeof TranslationContext>>(() => {
i18next.init({
fallbackLng: 'en',
defaultNS: 'project',
defaultNS: 'core',
resources: {
en: {
project: require('../../../packages/rocketchat-i18n/i18n/en.i18n.json'),
Expand Down

0 comments on commit 4422857

Please sign in to comment.