i18n-engine.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function i18n(identifier) {
  2. if (!i18n.db[i18n.locale]) {
  3. if (!i18n.db['en'][identifier]) {
  4. return "{MISSING_I18N_IDENTIFIER}";
  5. }
  6. return i18n.db['en'][identifier];
  7. }
  8. if (!i18n.db[i18n.locale][identifier]) {
  9. return "{MISSING_I18N_IDENTIFIER}";
  10. }
  11. return i18n.db[i18n.locale][identifier];
  12. }
  13. i18n.set = function(locale, identifier, translate) {
  14. if (!i18n.db[locale]) {
  15. i18n.db[locale] = {};
  16. }
  17. i18n.db[locale][identifier] = translate;
  18. }
  19. i18n.updateLocale = function(new_locale) {
  20. i18n.locale = new_locale;
  21. $( "data.i18n" ).each(function( index ) {
  22. $( this ).text(i18n($( this ).val()));
  23. });
  24. }
  25. i18n.locale = iLMparameters.lang;
  26. i18n.db = {};
  27. $.ajaxSetup({
  28. async: false
  29. });
  30. $.getJSON('i18n/i18n-database.json', function(data) {
  31. for (x in data) {
  32. l = data[x];
  33. i18n.set('en', x, l.en);
  34. i18n.set('es', x, l.es);
  35. i18n.set('pt', x, l.pt);
  36. }
  37. });
  38. $.ajaxSetup({
  39. async: true
  40. });
  41. $( document ).ready(function() {
  42. $( "data.i18n" ).each(function( index ) {
  43. $( this ).text(i18n($( this ).val()));
  44. });
  45. });