mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* 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
29 lines
908 B
TypeScript
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);
|
|
},
|
|
};
|