35 lines
784 B
JavaScript
35 lines
784 B
JavaScript
(function() {
|
|
'use strict';
|
|
|
|
// Global I18n registry that stores and serves translations.
|
|
// Each translation must have a unique ID.
|
|
window.I18n = (function() {
|
|
|
|
var translations = {};
|
|
|
|
function addTranslation(id, translation) {
|
|
translations[id] = translation;
|
|
}
|
|
|
|
function addManyTranslations(manyTranslations) {
|
|
Object.keys(manyTranslations).forEach(function(key) {
|
|
addTranslation(key, manyTranslations[key]);
|
|
});
|
|
}
|
|
|
|
function getTranslation(id) {
|
|
if (!translations[id]) {
|
|
return '(translation missing for »' + id + '«)';
|
|
}
|
|
return translations[id];
|
|
}
|
|
|
|
// public API
|
|
return {
|
|
add: addTranslation,
|
|
addMany: addManyTranslations,
|
|
get: getTranslation,
|
|
};
|
|
})();
|
|
})();
|