From 67b608b32460cbb72c064a1e1cf523d8f8dc8137 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 19 Mar 2016 14:30:07 +0800 Subject: [PATCH] set langs to config and modify gulp build to support langs --- Gulpfile.js | 31 +++++++++++++++++-------------- conf/app.conf | 2 ++ conf/app.conf-default | 5 ++++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Gulpfile.js b/Gulpfile.js index f1bd347..ec8d3f5 100644 --- a/Gulpfile.js +++ b/Gulpfile.js @@ -15,6 +15,8 @@ var base = leanoteBase + '/public'; // public base var noteDev = leanoteBase + '/app/views/note/note-dev.html'; var noteProBase = leanoteBase + '/app/views/note'; +var confFile = './conf/app.conf'; + // 合并Js, 这些js都是不怎么修改, 且是依赖 // 840kb, 非常耗时!! gulp.task('concatDepJs', function() { @@ -265,20 +267,21 @@ gulp.task('i18n', function() { fs.writeFile(base + '/js/i18n/' + toFilename, str); } - // 必须要的 - // keys.push(); - - genI18nJsFile('blog.zh-cn', [], keys); - genI18nJsFile('blog.zh-hk', [], keys); - genI18nJsFile('blog.en-us', [], keys); - genI18nJsFile('blog.fr-fr', [], keys); - genI18nJsFile('blog.pt-pt', [], keys); - - genI18nJsFile('msg.fr-fr', ['member.fr-fr', 'markdown.fr-fr', 'album.fr-fr'], keys); - genI18nJsFile('msg.zh-cn', ['member.zh-cn', 'markdown.zh-cn', 'album.zh-cn'], keys); - genI18nJsFile('msg.zh-hk', ['member.zh-hk', 'markdown.zh-hk', 'album.zh-hk'], keys); - genI18nJsFile('msg.en-us', ['member.en-us', 'markdown.en-us', 'album.en-us'], keys); - genI18nJsFile('msg.pt-pt', ['member.pt-pt', 'markdown.pt-pt', 'album.pt-pt'], keys); + // get all langs + /** + * i18n.languages=en-us,zh-cn,zh-hk,pt-pt,fr-fr + */ + var langs = ['zh-cn', 'zh-hk', 'en-us', 'fr-fr', 'pt-pt']; + var config = fs.readFileSync(confFile, 'utf-8'); + var langMatch = confFile.match(/i18n.languages=(.*)/); + if (langMatch) { + langs = langMatch[1].replace(/ /g, '').split(','); + } + for (var i = 0; i < langs.length; ++i) { + var lang = langs[i]; + genI18nJsFile('blog.' + lang, [], keys); + genI18nJsFile('msg.' + lang, ['member.' + lang, 'markdown.' + lang, 'album.' + lang], keys); + } }); // 合并album需要的js diff --git a/conf/app.conf b/conf/app.conf index 40b8131..f15f338 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -45,6 +45,8 @@ log.error.prefix = "ERROR " # The default language of this application. i18n.default_language=en-us +# All supported languages +i18n.languages=en-us,zh-cn,zh-hk,pt-pt,fr-fr module.static=github.com/revel/modules/static diff --git a/conf/app.conf-default b/conf/app.conf-default index 40b8131..c528840 100644 --- a/conf/app.conf-default +++ b/conf/app.conf-default @@ -18,7 +18,8 @@ db.password= # if not exists, please leave it blank # or you can set the mongodb url for more complex needs the format is: # mongodb://myuser:mypass@localhost:40001,otherhost:40001/mydb # db.url=mongodb://root:root123@localhost:27017/leanote -# db.urlEnv=${MONGODB_URL} # set url from env. eg. mongodb://root:root123@localhost:27017/leanote +# db.urlEnv=${MONGODB_URL} # set url from env. eg. +# mongodb://root:root123@localhost:27017/leanote # You Must Change It !! About Security!! app.secret=V85ZzBeTnzpsHyjQX4zukbQ8qqtju9y2aDM55VWxAH9Qop19poekx3xkcDVvrD0y @@ -45,6 +46,8 @@ log.error.prefix = "ERROR " # The default language of this application. i18n.default_language=en-us +# All supported languages +i18n.languages=en-us,zh-cn,zh-hk,pt-pt,fr-fr module.static=github.com/revel/modules/static