vendor/willdurand/js-translation-bundle/Resources/js/translatorTest.js

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

module('Translator', {
    setup: function() {
        Translator.reset();
    }
});

test('api definition', function() {
    expect(5);

    ok(Translator, 'Translator is defined');
    ok($.isFunction(Translator.trans), 'Translator.trans is a function');
    ok($.isFunction(Translator.transChoice), 'Translator.transChoice is a function');
    ok($.isFunction(Translator.add), 'Translator.add is a function');
    ok($.isFunction(Translator.fromJSON), 'Translator.fromJSON is a function');
});

test('add()', function() {
    expect(1);

    strictEqual(Translator.add('foo', 'bar'), Translator, 'The add method returns a Translator');
});

test('trans()', function() {
    expect(10);

    Translator.add('foo', 'bar', 'Foo');
    Translator.add('foo.with.arg', 'This is Ba %arg%');
    Translator.add('foo.with.arg', 'This is Ba %arg%', 'Foo');
    Translator.add('foo.with.args', 'There are %bananas% bananas and %apples% apples.', 'Foo');
    Translator.add('foo.with.replaces', '%repeat% %repeat% %repeat% !!!', 'Bar');
    Translator.add('empty', '', 'Foo');
    Translator.add('empty', '');

    // Basic
    equal(Translator.trans('foo', {}, 'Foo'), 'bar', 'Returns the correct message for the given key');
    equal(Translator.trans('foo.with.arg', {}, 'Foo'), 'This is Ba %arg%', 'Returns the correct message for the given key');
    equal(Translator.trans('foo.with.args', {}, 'Foo'), 'There are %bananas% bananas and %apples% apples.', 'Returns the correct message for the given key');

    equal(Translator.trans(''), '', 'Empty key returns empty message');
    equal(Translator.trans('unknown.key'), 'unknown.key', 'Unknown key returns the key as message');

    // Placeholders
    equal(Translator.trans('foo.with.arg', { arg: 'Bar' }, 'Foo'), 'This is Ba Bar', 'Returns the message with correct replaces');
    equal(Translator.trans('foo.with.args', { bananas: 10, apples: 2 }, 'Foo'), 'There are 10 bananas and 2 apples.', 'Returns the message with correct replaces');
    equal(Translator.trans('foo.with.replaces', { repeat: 'ah' }, 'Bar'), 'ah ah ah !!!', 'Returns the message with correct repeat replaces');

    // Empty string translations
    equal(Translator.trans('empty', {}, 'Foo'), '', 'An empty string translation should return the empty string and not the key.');

    // Message not in a domain with replaces
    equal(Translator.trans('Message not in the domain with %arg%', {arg: 'Bar'}), 'Message not in the domain with Bar', 'Message not in the domain with args returns the processed message');
});

test('transChoice()', function() {
    expect(31);

    Translator.add('foo.plural', '{0} Nothing|[1,Inf[ Many things', 'Foo');
    Translator.add('foo.plural.with.args', '{0} Nothing|{1} One thing|[2,Inf[ %count% things', 'Foo');
    Translator.add('foo.plural.with.inf', ']-Inf,0[ Underground|{0} Ground 0|{1} First level|[2,Inf[ High level', 'Foo');
    Translator.add('complex.plural', '{0} There is no apples|[20,Inf] There are many apples|There is one apple|a_few: There are %count% apples', 'Foo');

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。