From 268fc905de13edaf4af553ce18b3918e13f2f697 Mon Sep 17 00:00:00 2001
From: Peter Bengtsson
Date: Tue, 9 Mar 2021 16:59:28 -0500
Subject: [PATCH] Image flaw checking should be different for translated
content
Part of #3174
---
build/check-images.js | 26 +++++++++++++++++--
build/index.js | 1 +
.../files/fr/web/foo/index.html | 5 ++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/build/check-images.js b/build/check-images.js
index 46946c23cdd1..17311f4c07eb 100644
--- a/build/check-images.js
+++ b/build/check-images.js
@@ -133,13 +133,34 @@ function checkImageReferences(doc, $, options, { url, rawContent }) {
// We can use the `finalSrc` to look up and find the image independent
// of the correct case because `Image.findByURL` operates case
// insensitively.
- const filePath = Image.findByURL(finalSrc);
+ let filePath = Image.findByURL(finalSrc);
+ let enUSFallback = false;
+ if (
+ !filePath &&
+ doc.locale !== "en-US" &&
+ !finalSrc.startsWith("/en-us/")
+ ) {
+ const enFinalSrc = finalSrc.replace(
+ `/${doc.locale.toLowerCase()}/`,
+ "/en-us/"
+ );
+ if (Image.findByURL(enFinalSrc)) {
+ // Use the en-US src instead
+ finalSrc = enFinalSrc;
+ // Note that this `` value can work if you use the
+ // en-US equivalent URL instead.
+ enUSFallback = true;
+ }
+ }
if (filePath) {
filePaths.add(filePath);
}
if (checkImages) {
- if (!filePath) {
+ if (enUSFallback) {
+ // If it worked by switching to the en-US src, don't do anything more.
+ // Do nothing! I.e. don't try to perfect the spelling.
+ } else if (!filePath) {
// E.g. Foë