35 lines
834 B
JavaScript
35 lines
834 B
JavaScript
/**
|
|
* I18n
|
|
*
|
|
* This module stores and serves translated strings, according to the users language settings.
|
|
*
|
|
* Translations are stored in /messages/frontend/*.msg.
|
|
*
|
|
* To make additions to any of these files accessible to JavaScrip Utilities
|
|
* you need to add them to the respective *.msg file and to the list of FrontendMessages
|
|
* in /src/Utils/Frontend/I18n.hs.
|
|
*
|
|
*/
|
|
|
|
class I18n {
|
|
|
|
translations = {};
|
|
|
|
add(id, translation) {
|
|
this.translations[id] = translation;
|
|
}
|
|
|
|
addMany(manyTranslations) {
|
|
Object.keys(manyTranslations).forEach((key) => this.add(key, manyTranslations[key]));
|
|
}
|
|
|
|
get(id) {
|
|
if (!this.translations[id]) {
|
|
throw new Error('I18N Error: Translation missing for »' + id + '«!');
|
|
}
|
|
return this.translations[id];
|
|
}
|
|
}
|
|
|
|
window.I18n = new I18n();
|