1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-24 04:39:01 +00:00

Translation fixes (#5634)

This commit is contained in:
Paulus Schoutsen
2020-04-26 12:09:05 -07:00
committed by GitHub
parent 0d08f5413b
commit 7c6ba1a782
123 changed files with 17213 additions and 367 deletions

View File

@@ -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",
@@ -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",

View File

@@ -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",
@@ -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",

View File

@@ -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 = [];
@@ -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);
@@ -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) {
@@ -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);

View File

@@ -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",
@@ -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",

View File

@@ -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);
@@ -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);
@@ -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