gulp-i18next-translate
The main source code is inspired from this project. Big thanks to them.
$ npm install git+ssh:https://[email protected]/patw0929/gulp-i18next-translate.git --save-dev
The strings in HTML which needed to be translated should be wrapped by special characters (defined in functions
array):
<h1>__('Homepage')</h1>
__('http:https://patw.idv.tw')
<p>__('Will not be replaced')</p>
And the translation mapping json file is like this:
{
"Homepage": "首頁",
"Name": "姓名",
"http:https://patw.idv.tw": "http:https://patw.idv.tw/blog/",
"Will not be replaced": ""
}
It can generated by i18next-parser.
Through gulp task, we can make strings to be translated:
var translate = require('gulp-i18next-translate');
gulp.task('i18next-translate', function() {
gulp.src('./src/*.html')
.pipe(translate({
functions: ['__', '_e'],
locale: 'locales/*/translation.json'
}))
.pipe(gulp.dest('translated'));
});
Finally you can generate translated HTML files like:
<h1>首頁</h1>
http:https://patw.idv.tw/blog/
<p>Will not be replaced</p>