gulp-i18n-leverage
Advanced tools
Comparing version
{ | ||
"name": "gulp-i18n-leverage", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "Merge changes in default JSON into localized JSON for i18n-behavior", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -435,8 +435,9 @@ [](https://travis-ci.org/t2ym/gulp-i18n-leverage) | ||
### Integrate with polymer-cli project templates (highly experimental) | ||
### Integrate with Polymer CLI project templates or `polymer-build` library (highly experimental) | ||
#### Note: | ||
- As of [`polymer-cli 0.8.0`](https://github.com/Polymer/polymer-cli), `polymer` command and the project templates are pre-release and subject to change including the private API `userTransformers` on which this integration works. | ||
- As of [`Polymer CLI 0.12.0`](https://github.com/Polymer/polymer-cli), `polymer` command and the project templates are pre-release and subject to change including the private API `userTransformers` on which this integration works. | ||
- As of ['polymer-build 0.1.0'](https://github.com/Polymer/polymer-build), `polymer-build` library is pre-release and subject to change. | ||
#### Set up `package.json` and the dependent packages of the following `guilfile.js` | ||
#### Set up `package.json` and the dependent packages of the following `gulpfile.js` | ||
@@ -448,3 +449,3 @@ ```sh | ||
gulp-if gulp-ignore gulp-match gulp-merge gulp-size gulp-sort gulp-util \ | ||
json-stringify-safe strip-bom through2 xliff-conv | ||
json-stringify-safe strip-bom through2 xliff-conv polymer-build plylog merge-stream | ||
``` | ||
@@ -467,5 +468,8 @@ | ||
- `gulp locales --targets="{space separated list of target locales}"` | ||
- `gulp default` - Build with `polymer-build` library for `gulp` other than Polymer CLI | ||
#### [gulpfile.js](https://gist.github.com/t2ym/c37990e422d4a19774ba1d749510c1b8#file-gulpfile-js): Put it in the root folder of the project | ||
```javascript | ||
'use strict'; | ||
var gulp = require('gulp'); | ||
@@ -490,2 +494,12 @@ var gutil = require('gulp-util'); | ||
const logging = require('plylog'); | ||
const mergeStream = require('merge-stream'); | ||
const polymer = require('polymer-build'); | ||
//const optimize = require('polymer-build/lib/optimize').optimize; | ||
//const precache = require('polymer-build/lib/sw-precache'); | ||
const PolymerProject = polymer.PolymerProject; | ||
const fork = polymer.forkStream; | ||
const polymerConfig = require('./polymer.json'); | ||
// Global object to store localizable attributes repository | ||
@@ -501,2 +515,4 @@ var attributesRepository = {}; | ||
var xliffOptions = {}; | ||
// Scan HTMLs and construct localizable attributes repository | ||
@@ -540,3 +556,3 @@ var scan = gulpif('*.html', i18nPreprocess({ | ||
var bundleFileMap = {}; | ||
var xliffConv = new XliffConv(); | ||
var xliffConv = new XliffConv(xliffOptions); | ||
while (unbundleFiles.length > 0) { | ||
@@ -585,6 +601,7 @@ file = unbundleFiles.shift(); | ||
var base = bundleFiles[0].base; | ||
var xliffConv = new XliffConv(); | ||
var xliffConv = new XliffConv(xliffOptions); | ||
var srcLanguage = 'en'; | ||
var promises = []; | ||
var self = this; | ||
var lang; | ||
while (bundleFiles.length > 0) { | ||
@@ -596,3 +613,3 @@ file = bundleFiles.shift(); | ||
} | ||
for (var lang in bundles) { | ||
for (lang in bundles) { | ||
bundles[lang].bundle = true; | ||
@@ -607,3 +624,3 @@ this.push(new gutil.File({ | ||
} | ||
for (var lang in bundles) { | ||
for (lang in bundles) { | ||
if (lang) { | ||
@@ -671,2 +688,53 @@ (function (destLanguage) { | ||
}; | ||
//logging.setVerbose(); | ||
let project = new PolymerProject({ | ||
root: process.cwd(), | ||
entrypoint: polymerConfig.entrypoint, | ||
shell: polymerConfig.shell | ||
}); | ||
gulp.task('default', () => { | ||
// process source files in the project | ||
let sources = project.sources() | ||
.pipe(project.splitHtml()) | ||
// I18N processes | ||
.pipe(scan) | ||
.pipe(basenameSort) | ||
.pipe(dropDefaultJSON) | ||
.pipe(preprocess) | ||
.pipe(tmpJSON) | ||
.pipe(importXliff) | ||
.pipe(leverage) | ||
.pipe(exportXliff) | ||
.pipe(feedback) | ||
.pipe(debug({ title: title })) | ||
.pipe(size({ title: title })) | ||
// add compilers or optimizers here! | ||
.pipe(project.rejoinHtml()); | ||
// process dependencies | ||
let dependencies = project.dependencies() | ||
.pipe(project.splitHtml()) | ||
// add compilers or optimizers here! | ||
.pipe(project.rejoinHtml()); | ||
// merge the source and dependencies streams to we can analyze the project | ||
let allFiles = mergeStream(sources, dependencies) | ||
.pipe(project.analyze); | ||
// fork the stream in case downstream transformers mutate the files | ||
// this fork will vulcanize the project | ||
let bundled = fork(allFiles) | ||
.pipe(project.bundle) | ||
// write to the bundled folder | ||
.pipe(gulp.dest('build/bundled')); | ||
let unbundled = fork(allFiles) | ||
// write to the unbundled folder | ||
.pipe(gulp.dest('build/unbundled')); | ||
return mergeStream(bundled, unbundled); | ||
}); | ||
``` | ||
@@ -673,0 +741,0 @@ |
161153
1.48%799
9.3%