Skip to content
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 for BEMJSON #133

Open
wants to merge 1 commit into
base: i18n-bemjson
Choose a base branch
from
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
39 changes: 22 additions & 17 deletions .enb/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ module.exports = function(config) {
nodeConfig.addTechs([
// essential
[enbBemTechs.levels, { levels: levels }],
[techs.fileProvider, { target: '?.bemjson.js' }],
[enbBemTechs.bemjsonToBemdecl],
[enbBemTechs.deps],
[enbBemTechs.files],
[techs.fileProvider, { target: '?.{lang}.bemjson.js' }],
[enbBemTechs.bemjsonToBemdecl, { source: '?.{lang}.bemjson.js', target: '?.{lang}.bemdecl.js' }],
[enbBemTechs.deps, { target: '?.{lang}.deps.js', bemdeclFile: '?.{lang}.bemdecl.js' }],
[enbBemTechs.files, { filesTarget: '?.{lang}.files', dirsTarget: '?.{lang}.dirs', depsFile: '?.{lang}.deps.js' }],

// css
[techs.stylus, {
target: '?.css',
filesTarget: '?.{lang}.files',
target: '?.{lang}.css',
autoprefixer: {
browsers: ['ie >= 10', 'last 2 versions', 'opera 12.1', '> 2%']
}
}],


// keyset files for each language
[techs.keysets, { lang: '{lang}' }],
[techs.keysets, { lang: '{lang}', filesTarget: '?.{lang}.files', dirsTarget: '?.{lang}.dirs' }],

// i18n files for each language
[techs.i18n, { lang: '{lang}' }],
Expand All @@ -67,51 +69,54 @@ module.exports = function(config) {

// bemhtml
[techs.bemhtml, {
filesTarget: '?.{lang}.files',
lang: '{lang}',
devMode: process.env.BEMHTML_ENV === 'development'
}],

// html
[techs.bemjsonToHtml, {
bemjsonFile: '?.{lang}.bemjson.js',
bemhtmlFile: '?.bemhtml.{lang}.js',
target: '?.{lang}.html'
}],

// client bemhtml
[enbBemTechs.depsByTechToBemdecl, {
target: '?.bemhtml.bemdecl.js',
filesTarget: '?.{lang}.files',
target: '?.{lang}.bemhtml.bemdecl.js',
sourceTech: 'js',
destTech: 'bemhtml'
}],
[enbBemTechs.deps, {
target: '?.bemhtml.deps.js',
bemdeclFile: '?.bemhtml.bemdecl.js'
target: '?.{lang}.bemhtml.deps.js',
bemdeclFile: '?.{lang}.bemhtml.bemdecl.js'
}],
[enbBemTechs.files, {
depsFile: '?.bemhtml.deps.js',
filesTarget: '?.bemhtml.files',
dirsTarget: '?.bemhtml.dirs'
depsFile: '?.{lang}.bemhtml.deps.js',
filesTarget: '?.{lang}.bemhtml.files',
dirsTarget: '?.{lang}.bemhtml.dirs'
}],
[techs.bemhtml, {
lang: '{lang}',
target: '?.browser.{lang}.bemhtml.js',
filesTarget: '?.bemhtml.files',
filesTarget: '?.{lang}.bemhtml.files',
devMode: process.env.BEMHTML_ENV === 'development'
}],

// js
[techs.browserJs, { includeYM: true }],
[techs.browserJs, { includeYM: true, filesTarget: '?.{lang}.files', target: '?.{lang}.browser.js' }],
[techs.fileMerge, {
target: '?.{lang}.js',
sources: ['?.browser.js', '?.lang.{lang}.js', '?.browser.{lang}.bemhtml.js'],
sources: ['?.{lang}.browser.js', '?.lang.{lang}.js', '?.browser.{lang}.bemhtml.js'],
lang: '{lang}'
}],

// borschik
[techs.borschik, { source: '?.{lang}.js', target: '?.{lang}.min.js', minify: isProd }],
[techs.borschik, { source: '?.css', target: '?.min.css', tech: 'cleancss', minify: isProd }]
[techs.borschik, { source: '?.{lang}.css', target: '?.{lang}.min.css', tech: 'cleancss', minify: isProd }]
]);

nodeConfig.addTargets([/* '?.bemtree.js', */ '?.{lang}.html', '?.min.css', '?.{lang}.min.js']);
nodeConfig.addTargets([/* '?.bemtree.js', */ '?.{lang}.html', '?.{lang}.min.css', '?.{lang}.min.js']);
});
};
14 changes: 11 additions & 3 deletions common.blocks/page/page.bemhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ block('page')(
js()(true),
content()(function() {
return [
this.i18n('page', 'key'),
applyNext()
applyNext(),
' ',
this.i18n('page', 'key')
];
}),
// replace 'index.min.js' with 'index.{lang}.min.js'
// replace '?.min.css' with '?.{lang}.min.css'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а разве css может зависеть от языка?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

так как для каждого bemjson нужно собирать бандл в отдельной виртуальной файловой системе (не знаю как она правильно называется, я про ?.{lang}.files и ?.{lang}.dirs), то попытка всё сложить в один ?.min.css вызывает ошибку.
Не смог придумать как простым способом собирать общую технологию для всех bemjson.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно смёржить все декларации, полученные из BEMJSON-файла, и по этой декларации собрать CSS.

elem('css').match(function() { return this.ctx.i18n; }).def()(function() {
var url = this.ctx.url.split('.');
url.splice(1, 0, this.i18n('page', 'lang'));

return applyNext({ 'ctx.url': url.join('.') });
}),
// replace '?.min.js' with '?.{lang}.min.js'
elem('js').match(function() { return this.ctx.i18n; }).def()(function() {
var url = this.ctx.url.split('.');
url.splice(1, 0, this.i18n('page', 'lang'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ module.exports = {
head : [
{ elem : 'meta', attrs : { name : 'description', content : '' } },
{ elem : 'meta', attrs : { name : 'viewport', content : 'width=device-width, initial-scale=1' } },
{ elem : 'css', url : 'index.min.css' }
{ elem : 'css', url : 'index.min.css', i18n: true }
],
scripts: [
{ elem : 'js', url : 'index.min.js', i18n: true }
],
mods : { theme : 'islands' }
mods : { theme : 'islands' },
content : "Golden"
};
15 changes: 15 additions & 0 deletions desktop.bundles/index/index.ru.bemjson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
block : 'page',
title : 'Title of the page',
favicon : '/favicon.ico',
head : [
{ elem : 'meta', attrs : { name : 'description', content : '' } },
{ elem : 'meta', attrs : { name : 'viewport', content : 'width=device-width, initial-scale=1' } },
{ elem : 'css', url : 'index.min.css', i18n: true }
],
scripts: [
{ elem : 'js', url : 'index.min.js', i18n: true }
],
mods : { theme : 'islands' },
content : "Золотой"
};