lang.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //var langOptionHash = {}; // initialized in defaults.js
  2. fc.langs = langOptionHash; // expose
  3. // Initialize jQuery UI Datepicker translations while using some of the translations
  4. // for our own purposes. Will set this as the default language for datepicker.
  5. // Called from a translation file.
  6. fc.datepickerLang = function(langCode, datepickerLangCode, options) {
  7. var langOptions = langOptionHash[langCode];
  8. // initialize FullCalendar's lang hash for this language
  9. if (!langOptions) {
  10. langOptions = langOptionHash[langCode] = {};
  11. }
  12. // merge certain Datepicker options into FullCalendar's options
  13. mergeOptions(langOptions, {
  14. isRTL: options.isRTL,
  15. weekNumberTitle: options.weekHeader,
  16. titleFormat: {
  17. month: options.showMonthAfterYear ?
  18. 'YYYY[' + options.yearSuffix + '] MMMM' :
  19. 'MMMM YYYY[' + options.yearSuffix + ']'
  20. },
  21. defaultButtonText: {
  22. // the translations sometimes wrongly contain HTML entities
  23. prev: stripHTMLEntities(options.prevText),
  24. next: stripHTMLEntities(options.nextText),
  25. today: stripHTMLEntities(options.currentText)
  26. }
  27. });
  28. // is jQuery UI Datepicker is on the page?
  29. if ($.datepicker) {
  30. // Register the language data.
  31. // FullCalendar and MomentJS use language codes like "pt-br" but Datepicker
  32. // does it like "pt-BR" or if it doesn't have the language, maybe just "pt".
  33. // Make an alias so the language can be referenced either way.
  34. $.datepicker.regional[datepickerLangCode] =
  35. $.datepicker.regional[langCode] = // alias
  36. options;
  37. // Alias 'en' to the default language data. Do this every time.
  38. $.datepicker.regional.en = $.datepicker.regional[''];
  39. // Set as Datepicker's global defaults.
  40. $.datepicker.setDefaults(options);
  41. }
  42. };
  43. // Sets FullCalendar-specific translations. Also sets the language as the global default.
  44. // Called from a translation file.
  45. fc.lang = function(langCode, options) {
  46. var langOptions;
  47. if (options) {
  48. langOptions = langOptionHash[langCode];
  49. // initialize the hash for this language
  50. if (!langOptions) {
  51. langOptions = langOptionHash[langCode] = {};
  52. }
  53. mergeOptions(langOptions, options || {});
  54. }
  55. // set it as the default language for FullCalendar
  56. defaults.lang = langCode;
  57. };