-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n: refactor internals #576
Comments
Results from today discussions Current API: BEM.I18N.decl('block__elem', {
key1 : 'string',
key2 : function(params) {
return 'string';
},
key3 : function() {
BEM.I18N('i-tanker__dynamic', 'plural', { n : 5 });
this.keyset('i-tanker__dynamic').key('plural');
this.key('plural');
return this.key('key1');
},
plural : function() {
return i18n['tanker']['dynamic']['plural']({ n : 5 });
}
});
BEM.I18N('block__elem', 'key1');
BEM.I18N('block__elem', 'key2', { foo : 'bar' });
BEM.I18N.keyset('block__elem').key('key1');
i18n['prj']['keyset']['key'] = function() { return 'string '}; Future API modules.define('i18n', function(provide, i18n) {
var val = cache[..][..][..];
typeof val === 'string' ? val : val.call(i18n, params, i18n)
// Declaration of translations Object.<Lang.<Project.<Keyset.<Key>>>>
provide(i18n.decl({
ru : {
'bem-components' : {
button : {
file : 'f1',
file2 : function(params, i18n) {
i18n('bla', 'bla');
this('bla', 'bla');
this('bem-core', 'bla', 'bla', { b : 1 });
}
}
}
}
}));
}); Usage with modules.define('button', ['i18n'], function(provide, i18n, Button) {
i18n('button', ...);
provide(Button.declMod(...));
}); Usage with CommonJS (TBD): var i18n = require('page1.i18n.all.js');
i18n = i18n({ lang : 'ru', project : 'bem-core' });
i18n('i-tanker__dynamic', 'plural') // ru
i18n('bem-components', 'i-tanker__dynamic', 'plural') // ru
//i18n = i18n.lang('en')
var i18n = require('page1.i18n.ru.js');
i18n('i-tanker__dynamic', 'plural') // ru
i18n('i-tanker__dynamic', 'plural') // en Usage with // TODO: |
Thoughts:
|
Started working with @dfilatov. Decided to omit cases with multi languages in the same runtime for the first iteration. |
Why it not moved out of bem-bl/bem-core internals? What's the point to store it inside bem-core? |
Well, does it mean global language configuration? Some troubles with initialisation by |
@zxqfox it's used wiry widely (inside Yandex) — but there is no overhead for peoples who doesn't use it but may be we decide to move it out... let's wait for implementation |
@zxqfox yes — assumption about only one lang per runtime force some restrictions |
@veged I don't understand the problem ;-(. At my pov there is no troubles to load all translations and use the needed one (chosen by passed parameter). |
@zxqfox at least there is a problem to load all translations to browser anyway — we think about it a lot and consider that we can add such feature later (based on what we got and on really needs) |
@veged well, feels like incorrect arch. It's easy to make Nvm. I still asking about splitting i18n to separate package. |
@zxqfox you can't load all 100500 lang files to browser — also, there is a problem with async code, if you use answered about splitting behind — #576 (comment) |
@veged good catch. case with use in async mode should force us to make several ctxs of |
@veged In summary, it should be possible to merge some popular (or default) translations to |
@veged I also want to understand what's the problem with splitting |
@zxqfox I'm think we need to do first step as small as possible and as big as needed ;-) so we can come back to multi lang runtime feature and separation later |
@veged Got it. Thanks. |
See also bem/bem-bl#589 |
May be we can look (and reuse) some implementations inspired by |
modules.define('BEMHTML', ['i18n'], function(provide, i18n, BEMHTML) {
BEMHTML.BEMContext.prototype.i18n = i18n;
provide(BEMHTML);
});
/*
* TODO
*
* сделать технологию, которая будет билдить i18n
* сделать технологию, которая будет билдить browser.js+bemhtml+i18n
* сделать технологию, которая будет билдить browser.js+bh
* сделать технологию, которая будет билдить browser.js+bh+i18n
*
*
* */ |
cc @andrewblond |
|
ENB techs for the new |
|
Done. |
still need to port to |
No description provided.
The text was updated successfully, but these errors were encountered: