From 57e0a82174e074e1d8525bf383b623130eba9bc2 Mon Sep 17 00:00:00 2001 From: Pavel Bashinsky Date: Thu, 11 Feb 2016 20:03:42 +0300 Subject: [PATCH] i18n for BEMJSON --- .enb/make.js | 39 +++++++++++-------- common.blocks/page/page.bemhtml.js | 14 +++++-- .../{index.bemjson.js => index.en.bemjson.js} | 5 ++- desktop.bundles/index/index.ru.bemjson.js | 15 +++++++ 4 files changed, 51 insertions(+), 22 deletions(-) rename desktop.bundles/index/{index.bemjson.js => index.en.bemjson.js} (76%) create mode 100644 desktop.bundles/index/index.ru.bemjson.js diff --git a/.enb/make.js b/.enb/make.js index 50396fea..f223978c 100644 --- a/.enb/make.js +++ b/.enb/make.js @@ -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}' }], @@ -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']); }); }; diff --git a/common.blocks/page/page.bemhtml.js b/common.blocks/page/page.bemhtml.js index b8da81b5..654a9188 100644 --- a/common.blocks/page/page.bemhtml.js +++ b/common.blocks/page/page.bemhtml.js @@ -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' + 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')); diff --git a/desktop.bundles/index/index.bemjson.js b/desktop.bundles/index/index.en.bemjson.js similarity index 76% rename from desktop.bundles/index/index.bemjson.js rename to desktop.bundles/index/index.en.bemjson.js index aae21da0..f5e2fb8c 100644 --- a/desktop.bundles/index/index.bemjson.js +++ b/desktop.bundles/index/index.en.bemjson.js @@ -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" }; diff --git a/desktop.bundles/index/index.ru.bemjson.js b/desktop.bundles/index/index.ru.bemjson.js new file mode 100644 index 00000000..699fb33c --- /dev/null +++ b/desktop.bundles/index/index.ru.bemjson.js @@ -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 : "Золотой" +};