2
0

jsi18n-mocks.test.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. {
  3. const globals = this;
  4. const django = globals.django;
  5. django.pluralidx = function(count) { return (count === 1) ? 0 : 1; };
  6. /* gettext identity library */
  7. django.gettext = function(msgid) { return msgid; };
  8. django.ngettext = function(singular, plural, count) {
  9. return (count === 1) ? singular : plural;
  10. };
  11. django.gettext_noop = function(msgid) { return msgid; };
  12. django.pgettext = function(context, msgid) { return msgid; };
  13. django.npgettext = function(context, singular, plural, count) {
  14. return (count === 1) ? singular : plural;
  15. };
  16. django.interpolate = function(fmt, obj, named) {
  17. if (named) {
  18. return fmt.replace(/%\(\w+\)s/g, function(match) {
  19. return String(obj[match.slice(2, -2)]);
  20. });
  21. } else {
  22. return fmt.replace(/%s/g, function(match) {
  23. return String(obj.shift());
  24. });
  25. }
  26. };
  27. /* formatting library */
  28. django.formats = {
  29. "DATETIME_FORMAT": "N j, Y, P",
  30. "DATETIME_INPUT_FORMATS": [
  31. "%Y-%m-%d %H:%M:%S",
  32. "%Y-%m-%d %H:%M:%S.%f",
  33. "%Y-%m-%d %H:%M",
  34. "%Y-%m-%d",
  35. "%m/%d/%Y %H:%M:%S",
  36. "%m/%d/%Y %H:%M:%S.%f",
  37. "%m/%d/%Y %H:%M",
  38. "%m/%d/%Y",
  39. "%m/%d/%y %H:%M:%S",
  40. "%m/%d/%y %H:%M:%S.%f",
  41. "%m/%d/%y %H:%M",
  42. "%m/%d/%y"
  43. ],
  44. "DATE_FORMAT": "N j, Y",
  45. "DATE_INPUT_FORMATS": [
  46. "%Y-%m-%d",
  47. "%m/%d/%Y",
  48. "%m/%d/%y"
  49. ],
  50. "DECIMAL_SEPARATOR": ".",
  51. "FIRST_DAY_OF_WEEK": 0,
  52. "MONTH_DAY_FORMAT": "F j",
  53. "NUMBER_GROUPING": 3,
  54. "SHORT_DATETIME_FORMAT": "m/d/Y P",
  55. "SHORT_DATE_FORMAT": "m/d/Y",
  56. "THOUSAND_SEPARATOR": ",",
  57. "TIME_FORMAT": "P",
  58. "TIME_INPUT_FORMATS": [
  59. "%H:%M:%S",
  60. "%H:%M:%S.%f",
  61. "%H:%M"
  62. ],
  63. "YEAR_MONTH_FORMAT": "F Y"
  64. };
  65. django.get_format = function(format_type) {
  66. const value = django.formats[format_type];
  67. if (typeof value === 'undefined') {
  68. return format_type;
  69. } else {
  70. return value;
  71. }
  72. };
  73. /* add to global namespace */
  74. globals.pluralidx = django.pluralidx;
  75. globals.gettext = django.gettext;
  76. globals.ngettext = django.ngettext;
  77. globals.gettext_noop = django.gettext_noop;
  78. globals.pgettext = django.pgettext;
  79. globals.npgettext = django.npgettext;
  80. globals.interpolate = django.interpolate;
  81. globals.get_format = django.get_format;
  82. };