1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-24 20:55:49 +00:00

Update translations

This commit is contained in:
Paulus Schoutsen
2020-04-18 23:01:40 -07:00
parent 91eabf3c38
commit 659da7bf80
49 changed files with 75 additions and 254 deletions

View File

@@ -20,7 +20,7 @@ const fullDir = workDir + "/full";
const coreDir = workDir + "/core";
const outDir = workDir + "/output";
String.prototype.rsplit = function(sep, maxsplit) {
String.prototype.rsplit = function (sep, maxsplit) {
var split = this.split(sep);
return maxsplit
? [split.slice(0, -maxsplit).join(sep)].concat(split.slice(-maxsplit))
@@ -45,7 +45,7 @@ const TRANSLATION_FRAGMENTS = [
function recursiveFlatten(prefix, data) {
let output = {};
Object.keys(data).forEach(function(key) {
Object.keys(data).forEach(function (key) {
if (typeof data[key] === "object") {
output = {
...output,
@@ -107,7 +107,12 @@ function lokaliseTransform(data, original, file) {
output[key] = lokaliseTransform(value, original, file);
} else {
output[key] = value.replace(re_key_reference, (match, key) => {
const replace = key.split("::").reduce((tr, k) => tr[k], original);
const replace = key.split("::").reduce((tr, k) => {
if (!tr) {
throw Error(`Invalid key placeholder ${key} in ${file.path}`);
}
return tr[k];
}, original);
if (typeof replace !== "string") {
throw Error(`Invalid key placeholder ${key} in ${file.path}`);
}
@@ -118,7 +123,7 @@ function lokaliseTransform(data, original, file) {
return output;
}
gulp.task("clean-translations", function() {
gulp.task("clean-translations", function () {
return del([workDir]);
});
@@ -129,7 +134,7 @@ gulp.task("ensure-translations-build-dir", (done) => {
done();
});
gulp.task("create-test-metadata", function(cb) {
gulp.task("create-test-metadata", function (cb) {
fs.writeFile(
workDir + "/testMetadata.json",
JSON.stringify({
@@ -147,7 +152,7 @@ gulp.task(
return gulp
.src(path.join(paths.translations_src, "en.json"))
.pipe(
transform(function(data, file) {
transform(function (data, file) {
return recursiveEmpty(data);
})
)
@@ -165,11 +170,11 @@ gulp.task(
* project is buildable immediately after merging new translation keys, since
* the Lokalise update to translations/en.json will not happen immediately.
*/
gulp.task("build-master-translation", function() {
gulp.task("build-master-translation", function () {
return gulp
.src(path.join(paths.translations_src, "en.json"))
.pipe(
transform(function(data, file) {
transform(function (data, file) {
return lokaliseTransform(data, data, file);
})
)
@@ -177,16 +182,16 @@ gulp.task("build-master-translation", function() {
.pipe(gulp.dest(workDir));
});
gulp.task("build-merged-translations", function() {
gulp.task("build-merged-translations", function () {
return gulp
.src([inDir + "/*.json", workDir + "/test.json"], { allowEmpty: true })
.pipe(
transform(function(data, file) {
transform(function (data, file) {
return lokaliseTransform(data, data, file);
})
)
.pipe(
foreach(function(stream, file) {
foreach(function (stream, file) {
// For each language generate a merged json file. It begins with the master
// translation as a failsafe for untranslated strings, and merges all parent
// tags into one file for each specific subtag
@@ -223,7 +228,7 @@ var taskName;
const splitTasks = [];
TRANSLATION_FRAGMENTS.forEach((fragment) => {
taskName = "build-translation-fragment-" + fragment;
gulp.task(taskName, function() {
gulp.task(taskName, function () {
// Return only the translations for this fragment.
return gulp
.src(fullDir + "/*.json")
@@ -242,7 +247,7 @@ TRANSLATION_FRAGMENTS.forEach((fragment) => {
});
taskName = "build-translation-core";
gulp.task(taskName, function() {
gulp.task(taskName, function () {
// Remove the fragment translations from the core translation.
return gulp
.src(fullDir + "/*.json")
@@ -259,7 +264,7 @@ gulp.task(taskName, function() {
splitTasks.push(taskName);
gulp.task("build-flattened-translations", function() {
gulp.task("build-flattened-translations", function () {
// Flatten the split versions of our translations, and move them into outDir
return gulp
.src(
@@ -269,7 +274,7 @@ gulp.task("build-flattened-translations", function() {
{ base: workDir }
)
.pipe(
transform(function(data) {
transform(function (data) {
// Polymer.AppLocalizeBehavior requires flattened json
return flatten(data);
})
@@ -351,7 +356,7 @@ gulp.task(
)
.pipe(merge({}))
.pipe(
transform(function(data) {
transform(function (data) {
const newData = {};
Object.entries(data).forEach(([key, value]) => {
// Filter out translations without native name.