servatrice/webclient/src/i18n-backend.ts
Jeremy Letto 9577ada171
Webatrice: i18n (#4562)
* implement i18n capability

* reset package.lock file

* remove custom fallback

* fix relative path for i18n files

* check for language support before fetch request

* add LanguageDropdown component, es translation file to prove functionality

* remove boilerplate

* bundle default english translation with app

* add missing file

* rollup component-level i18n files

* cleanup

Co-authored-by: Jeremy Letto <jeremy.letto@datasite.com>
2022-02-26 21:36:53 -06:00

21 lines
537 B
TypeScript

import { ModuleType } from 'i18next';
import { Language } from 'types';
class I18nBackend {
static type: ModuleType = 'backend';
static BASE_URL = `${process.env.PUBLIC_URL}/locales`;
read(language, namespace, callback) {
if (!Language[language]) {
callback(true, null);
return;
}
fetch(`${I18nBackend.BASE_URL}/${Language[language]}/${namespace}.json`)
.then(resp => resp.json().then(json => callback(null, json)))
.catch(error => callback(error, null));
}
}
export default I18nBackend;