Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/soft-cows-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

download translation files through CDN
10 changes: 5 additions & 5 deletions apps/meteor/client/providers/TranslationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLocalStorage, useMutableCallback } from '@rocket.chat/fuselage-hooks
import languages from '@rocket.chat/i18n/dist/languages';
import en from '@rocket.chat/i18n/src/locales/en.i18n.json';
import type { TranslationKey, TranslationContextValue } from '@rocket.chat/ui-contexts';
import { useMethod, useSetting, TranslationContext, useAbsoluteUrl } from '@rocket.chat/ui-contexts';
import { useMethod, useSetting, TranslationContext } from '@rocket.chat/ui-contexts';
import type i18next from 'i18next';
import I18NextHttpBackend from 'i18next-http-backend';
import sprintf from 'i18next-sprintf-postprocessor';
Expand All @@ -12,6 +12,7 @@ import React, { useEffect, useMemo } from 'react';
import { I18nextProvider, initReactI18next, useTranslation } from 'react-i18next';

import { CachedCollectionManager } from '../../app/ui-cached-collection/client';
import { getURL } from '../../app/utils/client';
import { i18n, addSprinfToI18n } from '../../app/utils/lib/i18n';
import { AppClientOrchestratorInstance } from '../../ee/client/apps/orchestrator';
import { applyCustomTranslations } from '../lib/utils/applyCustomTranslations';
Expand Down Expand Up @@ -39,8 +40,6 @@ const parseToJSON = (customTranslations: string): Record<string, Record<string,
const localeCache = new Map<string, Promise<string>>();

const useI18next = (lng: string): typeof i18next => {
const basePath = useAbsoluteUrl()('/i18n');

const customTranslations = useSetting('Custom_Translations');

const parsedCustomTranslations = useMemo(() => {
Expand Down Expand Up @@ -100,17 +99,18 @@ const useI18next = (lng: string): typeof i18next => {
partialBundledLanguages: true,
defaultNS: 'core',
backend: {
loadPath: `${basePath}/{{lng}}.json`,
loadPath: 'i18n/{{lng}}.json',
parse: (data: string, lngs?: string | string[], namespaces: string | string[] = []) =>
extractKeys(JSON.parse(data), lngs, namespaces),
request: (_options, url, _payload, callback) => {
const params = url.split('/');

const lng = params[params.length - 1];

let promise = localeCache.get(lng);

if (!promise) {
promise = fetch(url).then((res) => res.text());
promise = fetch(getURL(url)).then((res) => res.text());
localeCache.set(lng, promise);
}

Expand Down