Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build-scripts/gulp/cast.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gulp.task(
process.env.IS_CAST = "true";
},
"clean-cast",
"translations-enable-merge-backend",
gulp.parallel(
"gen-icons-app",
"gen-icons-mdi",
Expand All @@ -34,6 +35,7 @@ gulp.task(
process.env.NODE_ENV = "production";
},
"clean-cast",
"translations-enable-merge-backend",
gulp.parallel("gen-icons-app", "gen-icons-mdi", "build-translations"),
"copy-static-cast",
"webpack-prod-cast",
Expand Down
3 changes: 3 additions & 0 deletions build-scripts/gulp/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gulp.task(
process.env.NODE_ENV = "development";
},
"clean-demo",
"translations-enable-merge-backend",
gulp.parallel(
"gen-icons-app",
"gen-icons-mdi",
Expand All @@ -35,6 +36,8 @@ gulp.task(
process.env.NODE_ENV = "production";
},
"clean-demo",
// Cast needs to be backwards compatible and older HA has no translations
"translations-enable-merge-backend",
gulp.parallel(
"gen-icons-app",
"gen-icons-mdi",
Expand Down
12 changes: 6 additions & 6 deletions build-scripts/gulp/download_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const del = require("del");
const gulp = require("gulp");
const mapStream = require("map-stream");

const inDir = "translations";
const inDir = "translations/frontend";
const downloadDir = inDir + "/downloads";

const tasks = [];
Expand All @@ -12,7 +12,7 @@ function hasHtml(data) {
}

function recursiveCheckHasHtml(file, data, errors, recKey) {
Object.keys(data).forEach(function(key) {
Object.keys(data).forEach(function (key) {
if (typeof data[key] === "object") {
const nextRecKey = recKey ? `${recKey}.${key}` : key;
recursiveCheckHasHtml(file, data[key], errors, nextRecKey);
Expand All @@ -25,7 +25,7 @@ function recursiveCheckHasHtml(file, data, errors, recKey) {
function checkHtml() {
const errors = [];

return mapStream(function(file, cb) {
return mapStream(function (file, cb) {
const content = file.contents;
let error;
if (content) {
Expand All @@ -42,19 +42,19 @@ function checkHtml() {
}

let taskName = "clean-downloaded-translations";
gulp.task(taskName, function() {
gulp.task(taskName, function () {
return del([`${downloadDir}/**`]);
});
tasks.push(taskName);

taskName = "check-translations-html";
gulp.task(taskName, function() {
gulp.task(taskName, function () {
return gulp.src(`${downloadDir}/*.json`).pipe(checkHtml());
});
tasks.push(taskName);

taskName = "move-downloaded-translations";
gulp.task(taskName, function() {
gulp.task(taskName, function () {
return gulp.src(`${downloadDir}/*.json`).pipe(gulp.dest(inDir));
});
tasks.push(taskName);
Expand Down
2 changes: 2 additions & 0 deletions build-scripts/gulp/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gulp.task(
process.env.NODE_ENV = "development";
},
"clean-gallery",
"translations-enable-merge-backend",
gulp.parallel("gen-icons-app", "gen-icons-mdi", "build-translations"),
"copy-static-gallery",
"gen-index-gallery-dev",
Expand All @@ -30,6 +31,7 @@ gulp.task(
process.env.NODE_ENV = "production";
},
"clean-gallery",
"translations-enable-merge-backend",
gulp.parallel("gen-icons-app", "gen-icons-mdi", "build-translations"),
"copy-static-gallery",
"webpack-prod-gallery",
Expand Down
32 changes: 27 additions & 5 deletions build-scripts/gulp/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ const { mapFiles } = require("../util");
const env = require("../env");
const paths = require("../paths");

const inDir = "translations";
const inFrontendDir = "translations/frontend";
const inBackendDir = "translations/backend";
const workDir = "build-translations";
const fullDir = workDir + "/full";
const coreDir = workDir + "/core";
const outDir = workDir + "/output";
let mergeBackend = false;

gulp.task("translations-enable-merge-backend", (done) => {
mergeBackend = true;
done();
});

String.prototype.rsplit = function (sep, maxsplit) {
var split = this.split(sep);
Expand Down Expand Up @@ -171,20 +178,32 @@ gulp.task(
* the Lokalise update to translations/en.json will not happen immediately.
*/
gulp.task("build-master-translation", function () {
const src = [path.join(paths.translations_src, "en.json")];

if (mergeBackend) {
src.push(path.join(inBackendDir, "en.json"));
}

return gulp
.src(path.join(paths.translations_src, "en.json"))
.src(src)
.pipe(
transform(function (data, file) {
return lokaliseTransform(data, data, file);
})
)
.pipe(rename("translationMaster.json"))
.pipe(
merge({
fileName: "translationMaster.json",
})
)
.pipe(gulp.dest(workDir));
});

gulp.task("build-merged-translations", function () {
return gulp
.src([inDir + "/*.json", workDir + "/test.json"], { allowEmpty: true })
.src([inFrontendDir + "/*.json", workDir + "/test.json"], {
allowEmpty: true,
})
.pipe(
transform(function (data, file) {
return lokaliseTransform(data, data, file);
Expand All @@ -207,7 +226,10 @@ gulp.task("build-merged-translations", function () {
if (lang === "test") {
src.push(workDir + "/test.json");
} else if (lang !== "en") {
src.push(inDir + "/" + lang + ".json");
src.push(inFrontendDir + "/" + lang + ".json");
if (mergeBackend) {
src.push(inBackendDir + "/" + lang + ".json");
}
}
}
return gulp
Expand Down
Loading