Skip to content
Snippets Groups Projects
Unverified Commit 919fe1f3 authored by gabriellsh's avatar gabriellsh Committed by Diego Sampaio
Browse files

chore: get translations from CDN (#30331)

parent 5e3473a2
No related branches found
No related tags found
No related merge requests found
---
"@rocket.chat/meteor": patch
---
download translation files through CDN
......@@ -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';
......@@ -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';
......@@ -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(() => {
......@@ -105,17 +104,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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment