Skip to content

Commit b2f424a

Browse files
authored
Merge pull request home-assistant#5586 from home-assistant/dev
20200422.0
2 parents 05495af + a9d9275 commit b2f424a

File tree

202 files changed

+17376
-12215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+17376
-12215
lines changed

build-scripts/gulp/cast.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ gulp.task(
1313
gulp.series(
1414
async function setEnv() {
1515
process.env.NODE_ENV = "development";
16+
process.env.IS_CAST = "true";
1617
},
1718
"clean-cast",
1819
gulp.parallel(

build-scripts/gulp/translations.js

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const fullDir = workDir + "/full";
2020
const coreDir = workDir + "/core";
2121
const outDir = workDir + "/output";
2222

23-
String.prototype.rsplit = function(sep, maxsplit) {
23+
String.prototype.rsplit = function (sep, maxsplit) {
2424
var split = this.split(sep);
2525
return maxsplit
2626
? [split.slice(0, -maxsplit).join(sep)].concat(split.slice(-maxsplit))
@@ -45,7 +45,7 @@ const TRANSLATION_FRAGMENTS = [
4545

4646
function recursiveFlatten(prefix, data) {
4747
let output = {};
48-
Object.keys(data).forEach(function(key) {
48+
Object.keys(data).forEach(function (key) {
4949
if (typeof data[key] === "object") {
5050
output = {
5151
...output,
@@ -107,7 +107,12 @@ function lokaliseTransform(data, original, file) {
107107
output[key] = lokaliseTransform(value, original, file);
108108
} else {
109109
output[key] = value.replace(re_key_reference, (match, key) => {
110-
const replace = key.split("::").reduce((tr, k) => tr[k], original);
110+
const replace = key.split("::").reduce((tr, k) => {
111+
if (!tr) {
112+
throw Error(`Invalid key placeholder ${key} in ${file.path}`);
113+
}
114+
return tr[k];
115+
}, original);
111116
if (typeof replace !== "string") {
112117
throw Error(`Invalid key placeholder ${key} in ${file.path}`);
113118
}
@@ -118,7 +123,7 @@ function lokaliseTransform(data, original, file) {
118123
return output;
119124
}
120125

121-
gulp.task("clean-translations", function() {
126+
gulp.task("clean-translations", function () {
122127
return del([workDir]);
123128
});
124129

@@ -129,7 +134,7 @@ gulp.task("ensure-translations-build-dir", (done) => {
129134
done();
130135
});
131136

132-
gulp.task("create-test-metadata", function(cb) {
137+
gulp.task("create-test-metadata", function (cb) {
133138
fs.writeFile(
134139
workDir + "/testMetadata.json",
135140
JSON.stringify({
@@ -147,7 +152,7 @@ gulp.task(
147152
return gulp
148153
.src(path.join(paths.translations_src, "en.json"))
149154
.pipe(
150-
transform(function(data, file) {
155+
transform(function (data, file) {
151156
return recursiveEmpty(data);
152157
})
153158
)
@@ -165,28 +170,28 @@ gulp.task(
165170
* project is buildable immediately after merging new translation keys, since
166171
* the Lokalise update to translations/en.json will not happen immediately.
167172
*/
168-
gulp.task("build-master-translation", function() {
173+
gulp.task("build-master-translation", function () {
169174
return gulp
170175
.src(path.join(paths.translations_src, "en.json"))
171176
.pipe(
172-
transform(function(data, file) {
177+
transform(function (data, file) {
173178
return lokaliseTransform(data, data, file);
174179
})
175180
)
176181
.pipe(rename("translationMaster.json"))
177182
.pipe(gulp.dest(workDir));
178183
});
179184

180-
gulp.task("build-merged-translations", function() {
185+
gulp.task("build-merged-translations", function () {
181186
return gulp
182187
.src([inDir + "/*.json", workDir + "/test.json"], { allowEmpty: true })
183188
.pipe(
184-
transform(function(data, file) {
189+
transform(function (data, file) {
185190
return lokaliseTransform(data, data, file);
186191
})
187192
)
188193
.pipe(
189-
foreach(function(stream, file) {
194+
foreach(function (stream, file) {
190195
// For each language generate a merged json file. It begins with the master
191196
// translation as a failsafe for untranslated strings, and merges all parent
192197
// tags into one file for each specific subtag
@@ -223,7 +228,7 @@ var taskName;
223228
const splitTasks = [];
224229
TRANSLATION_FRAGMENTS.forEach((fragment) => {
225230
taskName = "build-translation-fragment-" + fragment;
226-
gulp.task(taskName, function() {
231+
gulp.task(taskName, function () {
227232
// Return only the translations for this fragment.
228233
return gulp
229234
.src(fullDir + "/*.json")
@@ -242,12 +247,31 @@ TRANSLATION_FRAGMENTS.forEach((fragment) => {
242247
});
243248

244249
taskName = "build-translation-core";
245-
gulp.task(taskName, function() {
250+
gulp.task(taskName, function () {
246251
// Remove the fragment translations from the core translation.
247252
return gulp
248253
.src(fullDir + "/*.json")
249254
.pipe(
250-
transform((data) => {
255+
transform((data, file) => {
256+
// HACK to pull in old state translations for cast
257+
if (process.env.IS_CAST) {
258+
const legacyTranslationsPath = path.join(
259+
"cast/src/translations",
260+
file.relative
261+
);
262+
if (fs.existsSync(legacyTranslationsPath)) {
263+
const legacyStrings = JSON.parse(
264+
fs.readFileSync(legacyTranslationsPath, "utf-8")
265+
);
266+
// These 2 translations still exist today.
267+
if (legacyStrings.state && "default" in legacyStrings.state) {
268+
legacyStrings.default.unknown = data.state.default.unknown;
269+
legacyStrings.default.unavailable =
270+
data.state.default.unavailable;
271+
}
272+
data.state = legacyStrings.state;
273+
}
274+
}
251275
TRANSLATION_FRAGMENTS.forEach((fragment) => {
252276
delete data.ui.panel[fragment];
253277
});
@@ -259,7 +283,7 @@ gulp.task(taskName, function() {
259283

260284
splitTasks.push(taskName);
261285

262-
gulp.task("build-flattened-translations", function() {
286+
gulp.task("build-flattened-translations", function () {
263287
// Flatten the split versions of our translations, and move them into outDir
264288
return gulp
265289
.src(
@@ -269,7 +293,7 @@ gulp.task("build-flattened-translations", function() {
269293
{ base: workDir }
270294
)
271295
.pipe(
272-
transform(function(data) {
296+
transform(function (data) {
273297
// Polymer.AppLocalizeBehavior requires flattened json
274298
return flatten(data);
275299
})
@@ -351,7 +375,7 @@ gulp.task(
351375
)
352376
.pipe(merge({}))
353377
.pipe(
354-
transform(function(data) {
378+
transform(function (data) {
355379
const newData = {};
356380
Object.entries(data).forEach(([key, value]) => {
357381
// Filter out translations without native name.

build-scripts/webpack.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const createWebpackConfig = ({
7070
__BUILD__: JSON.stringify(latestBuild ? "latest" : "es5"),
7171
__VERSION__: JSON.stringify(version),
7272
__DEMO__: false,
73+
__BACKWARDS_COMPAT__: false,
7374
__STATIC_PATH__: "/static/",
7475
"process.env.NODE_ENV": JSON.stringify(
7576
isProdBuild ? "production" : "development"
@@ -221,6 +222,9 @@ const createCastConfig = ({ isProdBuild, latestBuild }) => {
221222
outputRoot: paths.cast_root,
222223
isProdBuild,
223224
latestBuild,
225+
defineOverlay: {
226+
__BACKWARDS_COMPAT__: true,
227+
},
224228
});
225229
};
226230

0 commit comments

Comments
 (0)