grafana/public/app/core/internationalization/loadTranslations.ts
Josh Hunt fe24404432
I18n: Support for Enterprise translations (#86215)
* I18n: Support for Enterprise translations

* don't attempt to link to enterprise in tests

* move extract script to makefile to optionally support enterprise

* update references to old extract script

* update docs

* thank god for unit tests
2024-04-18 16:25:27 +01:00

29 lines
908 B
TypeScript

import { BackendModule } from 'i18next';
import { LANGUAGES } from './constants';
const getLanguagePartFromCode = (code: string) => code.split('-')[0].toLowerCase();
export const loadTranslations: BackendModule = {
type: 'backend',
init() {},
async read(language, namespace, callback) {
let localeDef = LANGUAGES.find((v) => v.code === language);
if (!localeDef) {
localeDef = LANGUAGES.find((v) => getLanguagePartFromCode(v.code) === getLanguagePartFromCode(language));
}
if (!localeDef) {
return callback(new Error(`No message loader available for ${language}`), null);
}
const namespaceLoader = localeDef.loader[namespace];
if (!namespaceLoader) {
return callback(new Error(`No message loader available for ${language} with namespace ${namespace}`), null);
}
const messages = await namespaceLoader();
callback(null, messages);
},
};