⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
27 changes: 27 additions & 0 deletions locales.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface HelpLocales {
docusaurus: string;
crowdin: string;
}

export const helpLocales = [
{
docusaurus: "de",
crowdin: "de",
},
{
docusaurus: "es",
crowdin: "es-ES",
},
{
docusaurus: "fr",
crowdin: "fr",
},
{
docusaurus: "pt-BR",
crowdin: "pt-BR",
},
{
docusaurus: "id",
crowdin: "id",
},
] as HelpLocales[];
22 changes: 22 additions & 0 deletions regex_validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface RegexValidation {
expression: RegExp;
message: string;
filesToSkip?: string[];
}

export const regexValidations: RegexValidation[] = [
{
expression: /^---\n(.*?)\n---/s,
message: "front matter"
},
{
expression: /(?:(?=)({#[\d\w]+}))/gs,
message: "anchor",
filesToSkip: ["Community-Checking/enable-community-checking.md", "Draft-Generation/generating-a-draft.md"]
},
{
expression: /(?:(?=)(!\[\]\(\.\/[\d]+\.png\)))/gs,
message: "image",
filesToSkip: ["connect-paratext-project.md"]
}
]
149 changes: 2 additions & 147 deletions update.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// This doesn't fully solve the problem though, because metadata in the translated files may be different from the English files.

import { copy, readerFromStreamReader } from "jsr:@std/io";
import { walk } from "jsr:@std/fs/walk";
import { helpLocales } from "./locales.ts";
import { runChecks } from "./validate_docs.mts";

const projectId = Deno.env.get("CROWDIN_PROJECT_ID");
const apiKey = Deno.env.get("CROWDIN_API_KEY");
Expand Down Expand Up @@ -112,29 +113,6 @@ async function saveLatestBuild() {
}
}

const helpLocales = [
{
docusaurus: "de",
crowdin: "de",
},
{
docusaurus: "es",
crowdin: "es-ES",
},
{
docusaurus: "fr",
crowdin: "fr",
},
{
docusaurus: "pt-BR",
crowdin: "pt-BR",
},
{
docusaurus: "id",
crowdin: "id",
},
] as const;

async function copyDirContentsRecursive(
source: string,
dest: string
Expand Down Expand Up @@ -216,129 +194,6 @@ async function fetchNotionDocs() {
}
}

async function runChecks() {
// Check for malformed links in the i18n files

for await (const dirEntry of walk(`${projectRoot}/i18n`)) {
if (dirEntry.isFile && dirEntry.name.endsWith(".md")) {
const file = await Deno.readTextFile(dirEntry.path);
for (const [index, line] of file.split("\n").entries()) {
// Look for Markdown links that had a space added between the closing parenthesis and the opening bracket
if (/\]\s+\(/.test(line)) {
console.log(
`%cFound malformed link in ${dirEntry.path} at line ${index + 1}`,
"color: red"
);
console.log(line);
console.log(
" ".repeat(line.indexOf("]") + 1) + "%c^ Erroneous space",
"color: blue"
);
}
}
}
}

// Check that all original docs have a corresponding translation, and vice versa
const originalDocs = new Map<string, string>();
const docsDir = `${projectRoot}/docs`;
for await (const dirEntry of walk(docsDir)) {
if (dirEntry.isFile && dirEntry.name.endsWith(".md")) {
if (dirEntry.path.indexOf(docsDir) !== 0)
throw new Error("Unexpected path");
const relativePath = dirEntry.path.slice(docsDir.length + 1);
originalDocs.set(relativePath, await Deno.readTextFile(dirEntry.path));
}
}

for (const locale of helpLocales) {
const i18nDir = `${projectRoot}/i18n/${locale.docusaurus}/docusaurus-plugin-content-docs/current`;

const foundLocalizations = new Set<string>();

for await (const dirEntry of walk(i18nDir)) {
if (dirEntry.isFile && dirEntry.name.endsWith(".md")) {
if (dirEntry.path.indexOf(i18nDir) !== 0)
throw new Error("Unexpected path");

const relativePath = dirEntry.path.slice(i18nDir.length + 1);

foundLocalizations.add(relativePath);

if (!originalDocs.has(relativePath)) {
console.log(
`%cNo original document found for i18n file ${dirEntry.path}`,
"color: red"
);
}
}
}
for (const [relativePath, content] of originalDocs) {
if (!foundLocalizations.has(relativePath)) {
console.log(
`%cNo translation file found for ${relativePath} in ${i18nDir}`,
"color: red"
);
} else {
// Check that the front matter matches
const translation = await Deno.readTextFile(
`${i18nDir}/${relativePath}`
);
const frontMatterRegex = /^---\n(.*?)\n---/s;
const originalFrontMatterMatch = content.match(frontMatterRegex);
const translationFrontMatterMatch = translation.match(frontMatterRegex);
if (originalFrontMatterMatch == null) {
console.log(
`%cNo front matter found in original document ${relativePath}`,
"color: red"
);
}
if (translationFrontMatterMatch == null) {
console.log(
`%cNo front matter found in translation ${relativePath}`,
"color: red"
);
}

if (
originalFrontMatterMatch == null ||
translationFrontMatterMatch == null
)
continue;

const originalFrontMatter = originalFrontMatterMatch[1].split("\n");
const translationFrontMatter =
translationFrontMatterMatch[1].split("\n");

if (originalFrontMatter.length !== translationFrontMatter.length) {
console.log(
`%cFront matter length mismatch in ${relativePath} for locale ${locale.docusaurus}`,
"color: red"
);
}

for (const [index, line] of originalFrontMatter.entries()) {
// the title can change; everything else should match
if (line.indexOf("title: ") === 0) continue;
if (line !== translationFrontMatter[index]) {
console.log(
`%cFront matter mismatch in ${relativePath} for locale ${
locale.docusaurus
} at line ${index + 1}`,
"color: red"
);
console.log(`%cOriginal: ${line}`, "color: blue");
console.log(
`%cTranslation: ${translationFrontMatter[index]}`,
"color: blue"
);
}
}
}
}
}
}

try {
console.log("--- Deleting existing files ---");
await deleteExistingFiles();
Expand Down
Loading