Skip to content

Commit

Permalink
Image flaw checking should be different for translated content (mdn#3175
Browse files Browse the repository at this point in the history
)

* Image flaw checking should be different for translated content

Part of mdn#3174

* debugging be gone

* debugging be gone
  • Loading branch information
peterbe committed Jun 1, 2021
1 parent 2721a9e commit 3468202
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
25 changes: 23 additions & 2 deletions build/check-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<img src="...">` 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. <img src="doesnotexist.png"
addImageFlaw(img, src, {
explanation: "File not present on disk",
Expand Down
5 changes: 5 additions & 0 deletions testing/translated-content/files/fr/web/foo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
---

<p>Foë</p>

<figure>
<img src="screenshot.png" alt="Capture d'écran des couleurs" />
<figcaption>Une image parfaitement normale</figcaption>
</figure>

0 comments on commit 3468202

Please sign in to comment.