Add the Dark version to the data.js file and render it in the webpage.

This commit is contained in:
Benoit Marty
2024-03-08 12:07:26 +01:00
parent 4c062a6188
commit c7fa94e58f
3 changed files with 1001 additions and 978 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -110,6 +110,23 @@ function getNiceName(name) {
return name.substring(indices[2] + 1, indices[3]);
}
function createMissingImageElement() {
const text = document.createElement('p');
text.className = "missing";
text.textContent = 'No image';
return text;
}
function createImageElement(fullFile) {
const img = document.createElement('img');
img.className = "screenshot";
img.src = `${baseUrl}/${fullFile}`;
img.title = fullFile;
img.alt = "Missing image";
img.width = imageWidth;
return img;
}
function addTable() {
// Remove any previous table
document.getElementById('screenshots_container').innerHTML = '';
@@ -143,33 +160,26 @@ function addTable() {
}
const td = document.createElement('td');
if (languageIndex == 0) {
const fullFile = `${englishBasePath}/${englishFile}.png`;
const img = document.createElement('img');
img.className = "screenshot";
img.src = `${baseUrl}/${fullFile}`;
img.title = fullFile;
img.alt = "Missing image";
img.width = imageWidth;
td.appendChild(img);
// English file
td.appendChild(createImageElement(`${englishBasePath}/${englishFile}.png`));
} else if (languageIndex == 1) {
// Dark English file
if (screenshots[screenshotIndex][1].length > 0) {
hasTranslatedFiles = true;
td.appendChild(createImageElement(`${englishBasePath}/${screenshots[screenshotIndex][1]}.png`));
} else {
td.appendChild(createMissingImageElement());
}
} else {
let hasFile = screenshots[screenshotIndex][languageIndex];
if (hasFile === 0) {
const text = document.createElement('p');
text.className = "missing";
text.textContent = 'No image';
td.appendChild(text);
td.appendChild(createMissingImageElement());
} else {
hasTranslatedFiles = true;
// Foreign file is the same as the english file, replacing the language
const foreignFile = englishFile.replace("en]", `${dataLanguages[languageIndex]}]`).replace("_S_", "_T_")
const fullForeignFile = `${dataLanguages[languageIndex]}/${foreignFile}.png`;
const img = document.createElement('img');
img.className = "screenshot";
img.src = `${baseUrl}/${fullForeignFile}`;
img.title = fullForeignFile;
img.alt = "Missing image";
img.width = imageWidth;
td.appendChild(img);
td.appendChild(createImageElement(fullForeignFile));
}
}
tr.appendChild(td);

View File

@@ -100,21 +100,34 @@ def detectRecordedLanguages():
return sorted([f for f in os.listdir("screenshots") if len(f) == 2])
def computeDarkFileName(lightFileName):
if "-Day_0" in lightFileName:
return lightFileName.replace("-Day_0", "-Night_1")
match = re.match("(.*)-Day-(\d+)_(\d+)(.*)", lightFileName, flags=re.ASCII)
if match:
return match.group(1) + "-Night-" + match.group(2) + "_" + str((int(match.group(3)) + 1)) + match.group(4)
return ""
def generateJavascriptFile():
__doc__ = "Generate a javascript file to load the screenshots"
print("Generating javascript file...")
languages = detectRecordedLanguages()
# First item is the list of languages, adding "en" at the beginning
data = [["en"] + languages]
# First item is the list of languages, adding "en" and "en-dark" at the beginning
data = [["en", "en-dark"] + languages]
files = sorted(
os.listdir("tests/uitests/src/test/snapshots/images/"),
key=lambda file: file[file.find("_", 6):],
)
for file in files:
# Continue if file contains "-Night", keep only light screenshots (maybe the night screenshots could be on the second column?)
# Continue if file contains "-Night", keep only light screenshots
if "-Night" in file:
continue
dataForFile = [file[:-4]]
darkFile = computeDarkFileName(file)
if os.path.exists("./tests/uitests/src/test/snapshots/images/" + darkFile):
dataForFile.append(darkFile[:-4])
else:
dataForFile.append("")
for l in languages:
simpleFile = file[:3] + "T" + file[4:-7] + l + file[-5:-4]
translatedFile = "./screenshots/" + l + "/" + simpleFile + ".png"