@rr0/cms 0.3.42 → 0.3.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,17 +15,28 @@ export class LanguageReplaceCommand extends DomReplaceCommand {
|
|
|
15
15
|
const langInfo = inputFile.lang;
|
|
16
16
|
const variants = langInfo.variants;
|
|
17
17
|
const foundLang = langInfo.lang;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: "fr";
|
|
18
|
+
let pageLang;
|
|
19
|
+
const hasEnglishVariant = variants.includes("en");
|
|
20
|
+
if (hasEnglishVariant) {
|
|
21
|
+
pageLang = foundLang ? foundLang : "fr";
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (variants.includes("fr")) {
|
|
25
|
+
pageLang = foundLang && foundLang !== "fr" ? foundLang : "en";
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
pageLang = "fr";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
22
31
|
context.file.document.documentElement.lang = inputFile.lang.lang = pageLang;
|
|
23
32
|
const langVariants = variants.length == 1 && variants[0] == "" ? [pageLang == "fr" ? "en" : "fr"] : variants;
|
|
24
33
|
const fileName = inputFile.name;
|
|
25
34
|
for (let i = 0; i < langVariants.length; i++) {
|
|
26
35
|
const langVariant = langVariants[i];
|
|
27
36
|
const altLink = doc.createElement("a");
|
|
28
|
-
|
|
37
|
+
const toReplace = (foundLang ? "_" + foundLang : "") + ".";
|
|
38
|
+
const replacement = `${variants[i] == "" ? "" : "_" + langVariant}.`;
|
|
39
|
+
altLink.href = "/" + fileName.replace(toReplace, replacement);
|
|
29
40
|
const altText = langVariant === "en" ? "English version" : "Version française";
|
|
30
41
|
altLink.textContent = Buffer.from(altText, "utf-8").toString();
|
|
31
42
|
original.appendChild(altLink);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LanguageReplaceCommand } from "./LanguageReplaceCommand.js";
|
|
2
|
+
import { rr0TestUtil } from "../test/index.js";
|
|
3
|
+
import { describe, expect, test } from "@javarome/testscript";
|
|
4
|
+
describe("LanguageReplaceCommand", () => {
|
|
5
|
+
test("add default english translation", async () => {
|
|
6
|
+
const context = rr0TestUtil.time.newHtmlContext("1/9/6/8/CondonReport/index_fr.html", `<span id="alternate"/>`);
|
|
7
|
+
const command = new LanguageReplaceCommand();
|
|
8
|
+
await command.execute(context);
|
|
9
|
+
expect(context.file.contents).toBe(`<html lang="fr"><head><meta name="generator" content="ssg-api"></head><body><span id="alternate"><a href="/${rr0TestUtil.filePath(rr0TestUtil.time.filePath("1/9/6/8/CondonReport/index.html"))}">English version</a></span></body></html>`);
|
|
10
|
+
});
|
|
11
|
+
test("add english translation", async () => {
|
|
12
|
+
const context = rr0TestUtil.time.newHtmlContext("0/6/4/0/ChronicaMinor/index_fr.html", `<span id="alternate"/>`);
|
|
13
|
+
const command = new LanguageReplaceCommand();
|
|
14
|
+
await command.execute(context);
|
|
15
|
+
expect(context.file.contents).toBe(`<html lang="fr"><head><meta name="generator" content="ssg-api"></head><body><span id="alternate"><a href="/${rr0TestUtil.filePath(rr0TestUtil.time.filePath("0/6/4/0/ChronicaMinor/index_en.html"))}">English version</a></span></body></html>`);
|
|
16
|
+
});
|
|
17
|
+
test("add french translation from default", async () => {
|
|
18
|
+
const context = rr0TestUtil.time.newHtmlContext("1/9/6/8/CondonReport/index.html", `<span id="alternate"/>`);
|
|
19
|
+
const command = new LanguageReplaceCommand();
|
|
20
|
+
await command.execute(context);
|
|
21
|
+
expect(context.file.contents).toBe(`<html lang="en"><head><meta name="generator" content="ssg-api"></head><body><span id="alternate"><a href="/${rr0TestUtil.filePath(rr0TestUtil.time.filePath("1/9/6/8/CondonReport/index_fr.html"))}">Version française</a></span></body></html>`);
|
|
22
|
+
});
|
|
23
|
+
test("add french translation", async () => {
|
|
24
|
+
const context = rr0TestUtil.time.newHtmlContext("0/6/4/0/ChronicaMinor/index_en.html", `<span id="alternate"/>`);
|
|
25
|
+
const command = new LanguageReplaceCommand();
|
|
26
|
+
await command.execute(context);
|
|
27
|
+
expect(context.file.contents).toBe(`<html lang="en"><head><meta name="generator" content="ssg-api"></head><body><span id="alternate"><a href="/${rr0TestUtil.filePath(rr0TestUtil.time.filePath("0/6/4/0/ChronicaMinor/index_fr.html"))}">Version française</a></span></body></html>`);
|
|
28
|
+
});
|
|
29
|
+
});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@rr0/cms",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
|
|
5
|
-
"version": "0.3.
|
|
5
|
+
"version": "0.3.43",
|
|
6
6
|
"description": "RR0 Content Management System (CMS)",
|
|
7
7
|
"exports": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"circular-deps": "dpdm src",
|
|
26
26
|
"prepublishOnly": "npm run build && npm test",
|
|
27
27
|
"test": "testscript",
|
|
28
|
-
"test-one": "rm -Rf out && tsx src/
|
|
28
|
+
"test-one": "rm -Rf out && tsx src/lang/LanguageReplaceCommand.test.ts",
|
|
29
29
|
"test-ci": "rm -Rf out && testscript"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
"@rr0/time": "^0.11.1",
|
|
38
38
|
"canvas": "^3.1.0",
|
|
39
39
|
"csv-parser": "^3.2.0",
|
|
40
|
-
"glob": "^11.0.
|
|
41
|
-
"image-size": "^2.0.
|
|
42
|
-
"jsdom": "^26.
|
|
43
|
-
"selenium-webdriver": "^4.
|
|
40
|
+
"glob": "^11.0.2",
|
|
41
|
+
"image-size": "^2.0.2",
|
|
42
|
+
"jsdom": "^26.1.0",
|
|
43
|
+
"selenium-webdriver": "^4.32.0",
|
|
44
44
|
"ssg-api": "^1.16.15"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { LanguageReplaceCommand } from "./LanguageReplaceCommand.js";
|
|
2
|
-
import { rr0TestUtil } from "../test/index.js";
|
|
3
|
-
import { describe, expect, test } from "@javarome/testscript";
|
|
4
|
-
describe("LanguageReplaceCommand", () => {
|
|
5
|
-
test("add english translation", { skip: true }, async () => {
|
|
6
|
-
const context = rr0TestUtil.time.newHtmlContext("1/9/6/8/CondonReport/index_fr.html", `<span id="alternate"/>`);
|
|
7
|
-
const command = new LanguageReplaceCommand();
|
|
8
|
-
await command.execute(context);
|
|
9
|
-
expect(context.file.contents).toBe(`<html lang="fr"><head></head><body><span id="alternate"><a href="${rr0TestUtil.time.filePath("1/9/6/8/CondonReport/index_fr.html")}">English version</a></span></body></html>`);
|
|
10
|
-
});
|
|
11
|
-
test("add french translation", { skip: true }, async () => {
|
|
12
|
-
const context = rr0TestUtil.time.newHtmlContext("1/9/6/8/CondonReport/index.html", `<span id="alternate"/>`);
|
|
13
|
-
const command = new LanguageReplaceCommand();
|
|
14
|
-
await command.execute(context);
|
|
15
|
-
expect(context.file.contents).toBe(`<html lang="en"><head><meta name="generator" content="ssg-api"></head><body><span id="alternate"><a href="${rr0TestUtil.time.filePath("1/9/6/8/CondonReport/index_fr.html")}">Version française</a></span></body></html>`);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
File without changes
|