eesyphp/public_html/js/translation.js
Benjamin Renard 444c1ec2fc Improve translations
- Add support for translations in JavaScript code using babel lib and
  a custom PO file converter to JSON (using sepia/po-parser lib for
  PO files parsing)
- Put translation CLI commands in a dedicated file
- update_messages CLI command now provide PO file initialization feature
  using msginit and support of compendium files
2022-04-24 16:46:38 +02:00

26 lines
539 B
JavaScript

/*
* I18n
*/
var lang = null;
var translations;
function _(string) {
var translated = translations.gettext(string);
return (translated !== '') ? translated : string;
}
function ngettext(singular, plural, n) {
return translations.ngettext(singular, plural, n);
}
$(document).ready( function() {
// Load Gettext translations
var catalog = {};
$.getJSON('translations/'+lang+'.json', function(data) {
catalog = data;
}).always(function() {
translations = babel.Translations.load(catalog).install();
});
});