locale.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. define([
  2. './locales/ca.js',
  3. './locales/de.js',
  4. './locales/es.js',
  5. './locales/fr.js',
  6. './locales/it.js',
  7. './locales/nl.js',
  8. './locales/pl.js',
  9. './locales/pt_br.js',
  10. './locales/ro.js',
  11. './locales/ru.js',
  12. './locales/tr.js',
  13. './locales/vi.js',
  14. './locales/zh.js',
  15. './locales/zh_cn.js'
  16. ], function() {
  17. var langId = (navigator.language || navigator.userLanguage).toLowerCase().replace('-', '_');
  18. var language = langId.substr(0, 2);
  19. var locales = {};
  20. for (index in arguments) {
  21. for (property in arguments[index])
  22. locales[property] = arguments[index][property];
  23. }
  24. if ( ! locales['en'])
  25. locales['en'] = {};
  26. if ( ! locales[langId] && ! locales[language])
  27. language = 'en';
  28. var locale = (locales[langId] ? locales[langId] : locales[language]);
  29. function __(text) {
  30. var index = locale[text];
  31. if (index === undefined)
  32. return text;
  33. return index;
  34. };
  35. function setLanguage(language) {
  36. locale = locales[language];
  37. }
  38. return {
  39. __ : __,
  40. locales : locales,
  41. locale : locale,
  42. setLanguage: setLanguage
  43. };
  44. });