Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion scripts/i18n-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,19 @@ def protected_inline(text):
return Counter(kept)


def urls_of(text):
# A bare URL that ends a sentence picks up its full stop, which a
# translation may move or write as 。 or ।, so it is not part of the URL.
return [url.rstrip(".,;:!?") for url in URL_RE.findall(text)]
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved


def validate_manual(source, value):
from collections import Counter
if not isinstance(value, str) or not value.strip():
raise SyncError("empty translation")
if len(HEADING_RE.findall(source)) != len(HEADING_RE.findall(value)):
raise SyncError("heading count changed")
if sorted(URL_RE.findall(source)) != sorted(URL_RE.findall(value)):
if sorted(urls_of(source)) != sorted(urls_of(value)):
raise SyncError("URLs changed")
if Counter(FENCE_RE.findall(source)) != Counter(FENCE_RE.findall(value)):
raise SyncError("code block contents changed")
Expand Down
5 changes: 4 additions & 1 deletion test/shell.d/i18n-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ const englishTexts = {}
for (const file of englishManual) englishTexts[file] = fs.readFileSync(path.join(manualDir, file), 'utf8')
const bagOf = (items) => JSON.stringify([...items].sort())
const fencesOf = (text) => [...text.matchAll(/```[^\n]*\n([\s\S]*?)```/g)].map((m) => m[1])
const urlsOf = (text) => text.match(/https?:\/\/[^\s)]+/g) || []
// A bare URL that ends a sentence picks up its full stop, which a translation
// may move or write as 。 or ।, so trailing punctuation is not part of the URL.
const urlsOf = (text) => (text.match(/https?:\/\/[^\s)]+/g) || []).map((url) => url.replace(/[.,;:!?]+$/, ''))
const relDestsOf = (text) => [...text.matchAll(/\]\((?!<?https?:\/\/)([^)\s]+)/g)].map((m) => m[1])
const protectedInlineOf = (text) => [...text.matchAll(/`([^`\n]+)`/g)].map((m) => m[1])
.filter((span) => /[/~$]/.test(span) || span.startsWith('omarchy ') || span.startsWith('omarchy-'))
Expand All @@ -199,6 +201,7 @@ const fencedChapter = englishManual.find((file) => englishTexts[file].includes('
assert(manualProblems(englishTexts[fencedChapter], englishTexts[fencedChapter].replace(/```[^\n]*\n/, '$&echo tampered\n')).length > 0, 'the manual integrity check catches a changed code block')
const linkedChapter = englishManual.find((file) => /\]\(\d\d-[a-z0-9-]+\.md\)/.test(englishTexts[file]))
assert(manualProblems(englishTexts[linkedChapter], englishTexts[linkedChapter].replace(/\]\(\d\d-[a-z0-9-]+\.md\)/, '](99-missing.md)')).length > 0, 'the manual integrity check catches a broken chapter link')
assert(manualProblems('See https://example.org/walls.', 'https://example.org/walls を参照してください。').length === 0 && manualProblems('See https://example.org/walls.', 'See https://example.org/other.').length > 0, 'the manual integrity check ignores the full stop after a URL, not the URL')
for (const code of codes) {
if (code === 'en') continue
const dir = path.join(manualDir, code)
Expand Down
Loading