Requires

Provides

Locale.js

Provides methods for localization.

License:
MIT-style license
Authors:
Aaron Newton, Arian Stolwijk
  1. 27
  2. 28
  3. 29
  4. 30
  5. 31
  6. 32
  7. 33
  8. 34
  9. 35
  10. 36
  11. 37
  12. 38
  13. 39
  14. 40
  15. 41
  16. 42
  17. 43
  18. 44
  19. 45
  20. 46
  21. 47
(function(){ var current = 'en-US', data = { 'en-US': {} }, cascades = {}, cascadeMethods = {}; ['erase', 'include', 'reverse', 'sort', 'unshift', 'push', 'append', 'include'].each(function(method){ cascadeMethods[method] = function(){ cascades[current][method].apply(cascades[current], arguments); }; }); var Locale = this.Locale = { define: function(name, set, key, value){

<1.2compat>

  1. 49
  2. 50
if (name == 'cascades') return this.setCascades(current, set); if (set == 'cascades') return this.setCascades(name, key);

</1.2compat>

  1. 53
  2. 54
  3. 55
  4. 56
  5. 57
  6. 58
  7. 59
  8. 60
  9. 61
  10. 62
  11. 63
  12. 64
  13. 65
  14. 66
  15. 67
  16. 68
  17. 69
  18. 70
  19. 71
  20. 72
  21. 73
  22. 74
  23. 75
  24. 76
  25. 77
  26. 78
  27. 79
  28. 80
  29. 81
  30. 82
  31. 83
  32. 84
  33. 85
  34. 86
  35. 87
  36. 88
  37. 89
  38. 90
  39. 91
  40. 92
  41. 93
  42. 94
  43. 95
  44. 96
  45. 97
  46. 98
  47. 99
  48. 100
  49. 101
  50. 102
  51. 103
  52. 104
  53. 105
  54. 106
  55. 107
  56. 108
  57. 109
data[name] = data[name] || {}; data[name][set] = data[name][set] || {}; if (typeOf(key) == 'object'){ data[name][set] = Object.merge(data[name][set] || {}, key); } else { data[name][set][key] = value; } return this; }, setCurrent: function(name){ if (data[name]) current = name; this.fireEvent('change', name)/*<1.2compat>*/.fireEvent('langChange', name)/*</1.2compat>*/; return this; }, getCurrent: function(){ return current; }, get: function(key, args){ var locales = this.getCascades().clone().include('en-US'); locales.unshift(current); for (var i = 0; i < locales.length; i++){ var dataSet = data[locales[i]]; if (!dataSet) continue; var value = Object.getFromPath(dataSet, key); if (value != null) return (typeof value == 'function') ? value.apply(null, Array.from(args)) : value; } return null; }, setCascades: function(name, value){ cascades[name] = Array.from(value); return this; }, getCascades: function(name){ return cascades[name || current] || []; }, cascades: function(){ if (!cascades[current]) cascades[current] = []; return cascadeMethods; }, list: function(){ return Object.keys(data); } }; Object.append(Locale, new Events());

<1.2compat>

  1. 112
  2. 113
  3. 114
  4. 115
  5. 116
  6. 117
  7. 118
  8. 119
  9. 120
  10. 121
  11. 122
var lang = MooTools.lang = {}; lang.setLanguage = Locale.setCurrent; lang.getCurrentLanguage = Locale.getCurrent; lang.set = Locale.define; for (var key in Locale) lang[key] = Locale[key]; lang.get = function(set, key, args){ if (key) set += '.' + key; return Locale.get(set, args); };

</1.2compat>

  1. 125
})();