Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion blocks-common/i-bem/__i18n/i-bem__i18n.i18n/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,23 @@ bem_.I18N = (function(base) {
klass.key = function(name, params) {
var proto = this._proto,
result,
ksetRestored;
ksetRestored,
langRestored;

proto.lang(this._lang).key(name);

// TODO: kiss
result = proto.val.call(proto, params, klass);

// DEFAULT_LANG if not found translation
// instead of an empty string
if (result === '') {
langRestored = proto._lang;
proto.lang(DEFAULT_LANG);
result = proto.val.call(proto, params, klass);
proto.lang(langRestored);
}

// restoring keyset's context
// NOTE: should not save current ctx, `saveCtx = false`
ksetRestored = _popStack();
Expand Down
17 changes: 17 additions & 0 deletions blocks-common/i-bem/__i18n/test/test-i18n-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ suite('BEM.I18N Simple test', function() {

}, { "lang" : "ru" });


BEM.I18N.decl('i-keyset-0', {

"key1" : "Ключ1Кастом"

}, { "lang" : "custom" });

});

test('Simple', function() {
Expand All @@ -87,4 +94,14 @@ suite('BEM.I18N Simple test', function() {
assert.equal('Ключ1 : Ключ1', BEM.I18N('i-keyset-2', 'key', { }));
});

test('Simple language redeclaration', function() {
BEM.I18N.lang('custom');
assert.equal('Ключ1Кастом', BEM.I18N('i-keyset-0', 'key1'));
});

test('Simple as a fallback language in the default', function() {
BEM.I18N.lang('custom');
assert.equal('Ключ2', BEM.I18N('i-keyset-0', 'key2'));
});

});