123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import { nullTranslator } from '@jupyterlab/translation';
- describe('@jupyterlab/translation', () => {
- const trans = nullTranslator.load('some-domain');
- describe('BasicTranslator', () => {
- describe('#getInstance', () => {
- it('should return the instance of the EmptyTranslator', () => {
- expect(trans.gettext('Hello!')).toBe('Hello!');
- });
- });
- describe('#dummygettext', () => {
- it('should test whether the dummy bundle gettext/__ works', () => {
- // Shorthand method
- expect(trans.__('Hello!')).toBe('Hello!');
- expect(trans.__('Hello %1!', 'Joe')).toBe('Hello Joe!');
- // Normal method
- expect(trans.gettext('Hello!')).toBe('Hello!');
- expect(trans.gettext('Hello %1!', 'Joe')).toBe('Hello Joe!');
- });
- });
- describe('#dummypgettext', () => {
- it('should test whether the dummy bundle pgettext/_p works', () => {
- // Shorthand method
- expect(trans._p('Some context', 'Hello!')).toBe('Hello!');
- expect(trans._p('Some context', 'Hello %1!', 'Joe')).toBe('Hello Joe!');
- // Normal method
- expect(trans.pgettext('Some context', 'Hello!')).toBe('Hello!');
- expect(trans.pgettext('Some context', 'Hello %1!', 'Joe')).toBe(
- 'Hello Joe!'
- );
- });
- });
- describe('#dummyngettext', () => {
- it('should test whether the dummy bundle ngettext/_n works', () => {
- // Shorthand method
- expect(trans._n('I have %1 apple', 'I have %1 apples', 1)).toBe(
- 'I have 1 apple'
- );
- expect(trans._n('I have %1 apple', 'I have %1 apples', 2)).toBe(
- 'I have 2 apples'
- );
- expect(
- trans._n('I have %1 apple %2', 'I have %1 apples %2', 1, 'Joe')
- ).toBe('I have 1 apple Joe');
- expect(
- trans._n('I have %1 apple %2', 'I have %1 apples %2', 2, 'Joe')
- ).toBe('I have 2 apples Joe');
- // Normal method
- expect(trans.ngettext('I have %1 apple', 'I have %1 apples', 1)).toBe(
- 'I have 1 apple'
- );
- expect(trans.ngettext('I have %1 apple', 'I have %1 apples', 2)).toBe(
- 'I have 2 apples'
- );
- expect(
- trans.ngettext('I have %1 apple %2', 'I have %1 apples %2', 1, 'Joe')
- ).toBe('I have 1 apple Joe');
- expect(
- trans.ngettext('I have %1 apple %2', 'I have %1 apples %2', 2, 'Joe')
- ).toBe('I have 2 apples Joe');
- });
- });
- describe('#dummynpgettext', () => {
- it('should test whether the dummy bundle npgettext/_np works', () => {
- // Shorthand method
- expect(
- trans._np('Some context', 'I have %1 apple', 'I have %1 apples', 1)
- ).toBe('I have 1 apple');
- expect(
- trans._np('Some context', 'I have %1 apple', 'I have %1 apples', 2)
- ).toBe('I have 2 apples');
- expect(
- trans._np(
- 'Some context',
- 'I have %1 apple %2',
- 'I have %1 apples %2',
- 1,
- 'Joe'
- )
- ).toBe('I have 1 apple Joe');
- expect(
- trans._np(
- 'Some context',
- 'I have %1 apple %2',
- 'I have %1 apples %2',
- 2,
- 'Joe'
- )
- ).toBe('I have 2 apples Joe');
- // Normal method
- expect(
- trans.npgettext(
- 'Some context',
- 'I have %1 apple',
- 'I have %1 apples',
- 1
- )
- ).toBe('I have 1 apple');
- expect(
- trans.npgettext(
- 'Some context',
- 'I have %1 apple',
- 'I have %1 apples',
- 2
- )
- ).toBe('I have 2 apples');
- expect(
- trans.npgettext(
- 'Some context',
- 'I have %1 apple %2',
- 'I have %1 apples %2',
- 1,
- 'Joe'
- )
- ).toBe('I have 1 apple Joe');
- expect(
- trans.npgettext(
- 'Some context',
- 'I have %1 apple %2',
- 'I have %1 apples %2',
- 2,
- 'Joe'
- )
- ).toBe('I have 2 apples Joe');
- });
- });
- });
- describe('#dummydcnpgettext', () => {
- it('should test whether the dummy bundle dcnpgettext works', () => {
- expect(
- trans.dcnpgettext(
- 'jupyterlab',
- 'Some context',
- 'I have %1 apple',
- 'I have %1 apples',
- 1
- )
- ).toBe('I have 1 apple');
- expect(
- trans.dcnpgettext(
- 'jupyterlab',
- 'Some context',
- 'I have %1 apple',
- 'I have %1 apples',
- 2
- )
- ).toBe('I have 2 apples');
- expect(
- trans.dcnpgettext(
- 'jupyterlab',
- 'Some context',
- 'I have %1 apple %2',
- 'I have %1 apples %2',
- 1,
- 'Joe'
- )
- ).toBe('I have 1 apple Joe');
- expect(
- trans.dcnpgettext(
- 'jupyterlab',
- 'Some context',
- 'I have %1 apple %2',
- 'I have %1 apples %2',
- 2,
- 'Joe'
- )
- ).toBe('I have 2 apples Joe');
- });
- });
- });
|