Create dummy translation on dev (#3213)
parent
fe80c7fe0e
commit
642ba1adc3
|
@ -21,7 +21,7 @@ gulp.task(
|
||||||
"gen-icons",
|
"gen-icons",
|
||||||
"gen-pages-dev",
|
"gen-pages-dev",
|
||||||
"gen-index-app-dev",
|
"gen-index-app-dev",
|
||||||
"build-translations"
|
gulp.series("create-test-translation", "build-translations")
|
||||||
),
|
),
|
||||||
"copy-static",
|
"copy-static",
|
||||||
"webpack-watch-app"
|
"webpack-watch-app"
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const del = require("del");
|
const del = require("del");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
|
const fs = require("fs");
|
||||||
const foreach = require("gulp-foreach");
|
const foreach = require("gulp-foreach");
|
||||||
const hash = require("gulp-hash");
|
const hash = require("gulp-hash");
|
||||||
const hashFilename = require("gulp-hash-filename");
|
const hashFilename = require("gulp-hash-filename");
|
||||||
|
@ -72,6 +73,20 @@ function emptyFilter(data) {
|
||||||
return newData;
|
return newData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function recursiveEmpty(data) {
|
||||||
|
const newData = {};
|
||||||
|
Object.keys(data).forEach((key) => {
|
||||||
|
if (data[key]) {
|
||||||
|
if (typeof data[key] === "object") {
|
||||||
|
newData[key] = recursiveEmpty(data[key]);
|
||||||
|
} else {
|
||||||
|
newData[key] = "TRANSLATED";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return newData;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace Lokalise key placeholders with their actual values.
|
* Replace Lokalise key placeholders with their actual values.
|
||||||
*
|
*
|
||||||
|
@ -108,6 +123,37 @@ gulp.task(taskName, function() {
|
||||||
});
|
});
|
||||||
tasks.push(taskName);
|
tasks.push(taskName);
|
||||||
|
|
||||||
|
taskName = "create-test-metadata";
|
||||||
|
gulp.task(taskName, function(cb) {
|
||||||
|
fs.writeFile(
|
||||||
|
workDir + "/testMetadata.json",
|
||||||
|
JSON.stringify({
|
||||||
|
test: {
|
||||||
|
nativeName: "Test",
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
cb
|
||||||
|
);
|
||||||
|
});
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
|
taskName = "create-test-translation";
|
||||||
|
gulp.task(
|
||||||
|
taskName,
|
||||||
|
gulp.series("create-test-metadata", function() {
|
||||||
|
return gulp
|
||||||
|
.src("src/translations/en.json")
|
||||||
|
.pipe(
|
||||||
|
transform(function(data, file) {
|
||||||
|
return recursiveEmpty(data);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.pipe(rename("test.json"))
|
||||||
|
.pipe(gulp.dest(workDir));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
tasks.push(taskName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This task will build a master translation file, to be used as the base for
|
* This task will build a master translation file, to be used as the base for
|
||||||
* all languages. This starts with src/translations/en.json, and replaces all
|
* all languages. This starts with src/translations/en.json, and replaces all
|
||||||
|
@ -138,33 +184,38 @@ taskName = "build-merged-translations";
|
||||||
gulp.task(
|
gulp.task(
|
||||||
taskName,
|
taskName,
|
||||||
gulp.series("build-master-translation", function() {
|
gulp.series("build-master-translation", function() {
|
||||||
return gulp.src(inDir + "/*.json").pipe(
|
return gulp
|
||||||
foreach(function(stream, file) {
|
.src([inDir + "/*.json", workDir + "/test.json"], { allowEmpty: true })
|
||||||
// For each language generate a merged json file. It begins with the master
|
.pipe(
|
||||||
// translation as a failsafe for untranslated strings, and merges all parent
|
foreach(function(stream, file) {
|
||||||
// tags into one file for each specific subtag
|
// For each language generate a merged json file. It begins with the master
|
||||||
//
|
// translation as a failsafe for untranslated strings, and merges all parent
|
||||||
// TODO: This is a naive interpretation of BCP47 that should be improved.
|
// tags into one file for each specific subtag
|
||||||
// Will be OK for now as long as we don't have anything more complicated
|
//
|
||||||
// than a base translation + region.
|
// TODO: This is a naive interpretation of BCP47 that should be improved.
|
||||||
const tr = path.basename(file.history[0], ".json");
|
// Will be OK for now as long as we don't have anything more complicated
|
||||||
const subtags = tr.split("-");
|
// than a base translation + region.
|
||||||
const src = [workDir + "/translationMaster.json"];
|
const tr = path.basename(file.history[0], ".json");
|
||||||
for (let i = 1; i <= subtags.length; i++) {
|
const subtags = tr.split("-");
|
||||||
const lang = subtags.slice(0, i).join("-");
|
const src = [
|
||||||
src.push(inDir + "/" + lang + ".json");
|
workDir + "/translationMaster.json",
|
||||||
}
|
workDir + "/test.json",
|
||||||
return gulp
|
];
|
||||||
.src(src, { allowEmpty: true })
|
for (let i = 1; i <= subtags.length; i++) {
|
||||||
.pipe(transform((data) => emptyFilter(data)))
|
const lang = subtags.slice(0, i).join("-");
|
||||||
.pipe(
|
src.push(inDir + "/" + lang + ".json");
|
||||||
merge({
|
}
|
||||||
fileName: tr + ".json",
|
return gulp
|
||||||
})
|
.src(src, { allowEmpty: true })
|
||||||
)
|
.pipe(transform((data) => emptyFilter(data)))
|
||||||
.pipe(gulp.dest(fullDir));
|
.pipe(
|
||||||
})
|
merge({
|
||||||
);
|
fileName: tr + ".json",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.pipe(gulp.dest(fullDir));
|
||||||
|
})
|
||||||
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
tasks.push(taskName);
|
tasks.push(taskName);
|
||||||
|
@ -299,10 +350,14 @@ gulp.task(
|
||||||
taskName,
|
taskName,
|
||||||
gulp.series("build-translation-fingerprints", function() {
|
gulp.series("build-translation-fingerprints", function() {
|
||||||
return gulp
|
return gulp
|
||||||
.src([
|
.src(
|
||||||
"src/translations/translationMetadata.json",
|
[
|
||||||
workDir + "/translationFingerprints.json",
|
"src/translations/translationMetadata.json",
|
||||||
])
|
workDir + "/testMetadata.json",
|
||||||
|
workDir + "/translationFingerprints.json",
|
||||||
|
],
|
||||||
|
{ allowEmpty: true }
|
||||||
|
)
|
||||||
.pipe(merge({}))
|
.pipe(merge({}))
|
||||||
.pipe(
|
.pipe(
|
||||||
transform(function(data) {
|
transform(function(data) {
|
||||||
|
|
Loading…
Reference in New Issue