base.spec.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { nullTranslator } from '@jupyterlab/translation';
  4. describe('@jupyterlab/translation', () => {
  5. const trans = nullTranslator.load('some-domain');
  6. describe('BasicTranslator', () => {
  7. describe('#getInstance', () => {
  8. it('should return the instance of the EmptyTranslator', () => {
  9. expect(trans.gettext('Hello!')).toBe('Hello!');
  10. });
  11. });
  12. describe('#dummygettext', () => {
  13. it('should test whether the dummy bundle gettext/__ works', () => {
  14. // Shorthand method
  15. expect(trans.__('Hello!')).toBe('Hello!');
  16. expect(trans.__('Hello %1!', 'Joe')).toBe('Hello Joe!');
  17. // Normal method
  18. expect(trans.gettext('Hello!')).toBe('Hello!');
  19. expect(trans.gettext('Hello %1!', 'Joe')).toBe('Hello Joe!');
  20. });
  21. });
  22. describe('#dummypgettext', () => {
  23. it('should test whether the dummy bundle pgettext/_p works', () => {
  24. // Shorthand method
  25. expect(trans._p('Some context', 'Hello!')).toBe('Hello!');
  26. expect(trans._p('Some context', 'Hello %1!', 'Joe')).toBe('Hello Joe!');
  27. // Normal method
  28. expect(trans.pgettext('Some context', 'Hello!')).toBe('Hello!');
  29. expect(trans.pgettext('Some context', 'Hello %1!', 'Joe')).toBe(
  30. 'Hello Joe!'
  31. );
  32. });
  33. });
  34. describe('#dummyngettext', () => {
  35. it('should test whether the dummy bundle ngettext/_n works', () => {
  36. // Shorthand method
  37. expect(trans._n('I have %1 apple', 'I have %1 apples', 1)).toBe(
  38. 'I have 1 apple'
  39. );
  40. expect(trans._n('I have %1 apple', 'I have %1 apples', 2)).toBe(
  41. 'I have 2 apples'
  42. );
  43. expect(
  44. trans._n('I have %1 apple %2', 'I have %1 apples %2', 1, 'Joe')
  45. ).toBe('I have 1 apple Joe');
  46. expect(
  47. trans._n('I have %1 apple %2', 'I have %1 apples %2', 2, 'Joe')
  48. ).toBe('I have 2 apples Joe');
  49. // Normal method
  50. expect(trans.ngettext('I have %1 apple', 'I have %1 apples', 1)).toBe(
  51. 'I have 1 apple'
  52. );
  53. expect(trans.ngettext('I have %1 apple', 'I have %1 apples', 2)).toBe(
  54. 'I have 2 apples'
  55. );
  56. expect(
  57. trans.ngettext('I have %1 apple %2', 'I have %1 apples %2', 1, 'Joe')
  58. ).toBe('I have 1 apple Joe');
  59. expect(
  60. trans.ngettext('I have %1 apple %2', 'I have %1 apples %2', 2, 'Joe')
  61. ).toBe('I have 2 apples Joe');
  62. });
  63. });
  64. describe('#dummynpgettext', () => {
  65. it('should test whether the dummy bundle npgettext/_np works', () => {
  66. // Shorthand method
  67. expect(
  68. trans._np('Some context', 'I have %1 apple', 'I have %1 apples', 1)
  69. ).toBe('I have 1 apple');
  70. expect(
  71. trans._np('Some context', 'I have %1 apple', 'I have %1 apples', 2)
  72. ).toBe('I have 2 apples');
  73. expect(
  74. trans._np(
  75. 'Some context',
  76. 'I have %1 apple %2',
  77. 'I have %1 apples %2',
  78. 1,
  79. 'Joe'
  80. )
  81. ).toBe('I have 1 apple Joe');
  82. expect(
  83. trans._np(
  84. 'Some context',
  85. 'I have %1 apple %2',
  86. 'I have %1 apples %2',
  87. 2,
  88. 'Joe'
  89. )
  90. ).toBe('I have 2 apples Joe');
  91. // Normal method
  92. expect(
  93. trans.npgettext(
  94. 'Some context',
  95. 'I have %1 apple',
  96. 'I have %1 apples',
  97. 1
  98. )
  99. ).toBe('I have 1 apple');
  100. expect(
  101. trans.npgettext(
  102. 'Some context',
  103. 'I have %1 apple',
  104. 'I have %1 apples',
  105. 2
  106. )
  107. ).toBe('I have 2 apples');
  108. expect(
  109. trans.npgettext(
  110. 'Some context',
  111. 'I have %1 apple %2',
  112. 'I have %1 apples %2',
  113. 1,
  114. 'Joe'
  115. )
  116. ).toBe('I have 1 apple Joe');
  117. expect(
  118. trans.npgettext(
  119. 'Some context',
  120. 'I have %1 apple %2',
  121. 'I have %1 apples %2',
  122. 2,
  123. 'Joe'
  124. )
  125. ).toBe('I have 2 apples Joe');
  126. });
  127. });
  128. });
  129. describe('#dummydcnpgettext', () => {
  130. it('should test whether the dummy bundle dcnpgettext works', () => {
  131. expect(
  132. trans.dcnpgettext(
  133. 'jupyterlab',
  134. 'Some context',
  135. 'I have %1 apple',
  136. 'I have %1 apples',
  137. 1
  138. )
  139. ).toBe('I have 1 apple');
  140. expect(
  141. trans.dcnpgettext(
  142. 'jupyterlab',
  143. 'Some context',
  144. 'I have %1 apple',
  145. 'I have %1 apples',
  146. 2
  147. )
  148. ).toBe('I have 2 apples');
  149. expect(
  150. trans.dcnpgettext(
  151. 'jupyterlab',
  152. 'Some context',
  153. 'I have %1 apple %2',
  154. 'I have %1 apples %2',
  155. 1,
  156. 'Joe'
  157. )
  158. ).toBe('I have 1 apple Joe');
  159. expect(
  160. trans.dcnpgettext(
  161. 'jupyterlab',
  162. 'Some context',
  163. 'I have %1 apple %2',
  164. 'I have %1 apples %2',
  165. 2,
  166. 'Joe'
  167. )
  168. ).toBe('I have 2 apples Joe');
  169. });
  170. });
  171. });