diff --git a/README.md b/README.md index 81edcc0c3c3..302b5ad4037 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,8 @@ all locales with `npm run build` before submitting a change. When changing or adding an English guide, review and update all seven translations in the same delivery. Review the prose for fluent language and the technical contract for accuracy. Keep executable code blocks -identical to the English source. The build checks this for Spanish, Brazilian -Portuguese, Simplified Chinese, Japanese, French and German. A missing translation +identical to the English source. The build checks this for German, Spanish, +French, Brazilian Portuguese, Ukrainian, Japanese and Simplified Chinese. A missing translation or English fallback does not satisfy a changed guide's acceptance. Artifact version placeholders stay shared with English and update automatically. diff --git a/i18n/uk/docusaurus-plugin-content-docs/current/waterline-operator-api.md b/i18n/uk/docusaurus-plugin-content-docs/current/waterline-operator-api.md index d51266ad4a9..c310cf80fbf 100644 --- a/i18n/uk/docusaurus-plugin-content-docs/current/waterline-operator-api.md +++ b/i18n/uk/docusaurus-plugin-content-docs/current/waterline-operator-api.md @@ -67,7 +67,7 @@ Waterline підтримує англійську, бразильську пор Laravel-застосунку або контейнера сервісу: ```dotenv -WATERLINE_LOCALE=uk +WATERLINE_LOCALE=es ``` | Мова | Налаштування | diff --git a/scripts/check-doc-translation-updates.js b/scripts/check-doc-translation-updates.js index 869c5842b68..5146ae175e7 100644 --- a/scripts/check-doc-translation-updates.js +++ b/scripts/check-doc-translation-updates.js @@ -1,9 +1,19 @@ +const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const {createHash} = require('node:crypto'); const {execFileSync} = require('node:child_process'); -const locales = ['de', 'es', 'fr', 'pt-BR', 'uk', 'ja', 'zh-Hans']; +const localeLabels = { + de: 'German', + es: 'Spanish', + fr: 'French', + 'pt-BR': 'Brazilian Portuguese', + uk: 'Ukrainian', + ja: 'Japanese', + 'zh-Hans': 'Simplified Chinese', +}; +const locales = Object.keys(localeLabels); function translationFailures(root, locale, relative, source, hash) { const localeRoot = path.join(root, 'i18n', locale); @@ -83,4 +93,46 @@ function checkTranslationUpdatesFromGit(root) { console.log(`Translation updates match reviewed English sources for ${count} changed guides in all seven other locales.`); } -module.exports = {checkTranslationUpdates, checkCurrentTranslations, checkTranslationUpdatesFromGit}; +function codeBlocks(file) { + const text = fs.readFileSync(file, 'utf8'); + return [...text.matchAll(/^```[^\n]*\n[\s\S]*?^```\s*$/gm)].map(match => match[0].trimEnd()); +} + +// Every offered locale keeps its executable examples identical to English. +// Returns, per locale, the current English source hash of each checked guide. +function checkCodeBlocks(root, languages = locales) { + const hashes = {}; + for (const locale of languages) { + const label = localeLabels[locale] ?? locale; + const translatedRoot = path.join(root, 'i18n', locale, 'docusaurus-plugin-content-docs/current'); + const current = {}; + + function visit(directory) { + for (const entry of fs.readdirSync(directory, {withFileTypes: true})) { + const file = path.join(directory, entry.name); + if (entry.isDirectory()) { + visit(file); + } else if (entry.isFile() && /\.mdx?$/.test(entry.name)) { + const relative = path.relative(translatedRoot, file).split(path.sep).join('/'); + const source = path.join(root, 'docs', relative); + assert.deepEqual(codeBlocks(file), codeBlocks(source), + `${label} executable examples differ from English: ${relative}`); + current[relative] = createHash('sha256').update(fs.readFileSync(source)).digest('hex'); + } + } + } + + visit(translatedRoot); + hashes[locale] = current; + } + return hashes; +} + +module.exports = { + locales, + localeLabels, + checkTranslationUpdates, + checkCurrentTranslations, + checkTranslationUpdatesFromGit, + checkCodeBlocks, +}; diff --git a/scripts/check-doc-translation-updates.test.js b/scripts/check-doc-translation-updates.test.js index 64819c48826..cb975d9ae46 100644 --- a/scripts/check-doc-translation-updates.test.js +++ b/scripts/check-doc-translation-updates.test.js @@ -4,7 +4,12 @@ const os = require('node:os'); const path = require('node:path'); const {createHash} = require('node:crypto'); const {test} = require('node:test'); -const {checkTranslationUpdates, checkCurrentTranslations} = require('./check-doc-translation-updates'); +const { + locales, + checkTranslationUpdates, + checkCurrentTranslations, + checkCodeBlocks, +} = require('./check-doc-translation-updates'); const root = fs.mkdtempSync(path.join(os.tmpdir(), 'doc-translation-updates-')); const relative = 'features/timers.md'; @@ -119,3 +124,24 @@ test('full inventory requires all seven offered non-English locales', t => { } assert.equal(checkCurrentTranslations(directory), 2); }); + +test('code block check covers every offered locale, including Ukrainian', t => { + const directory = inventoryFixture(t); + const english = '# Locale\n\nSet it:\n\n```dotenv\nWATERLINE_LOCALE=es\n```\n'; + const localized = '# Localized\n\nSet it:\n\n```dotenv\nWATERLINE_LOCALE=es\n```\n'; + write(path.join(directory, 'docs/locale.md'), english); + for (const locale of locales) { + translate(directory, locale, 'locale.md', english, localized); + } + + assert.deepEqual(locales, ['de', 'es', 'fr', 'pt-BR', 'uk', 'ja', 'zh-Hans']); + const hashes = checkCodeBlocks(directory); + assert.deepEqual(Object.keys(hashes), locales); + assert.equal(hashes.uk['locale.md'], createHash('sha256').update(english).digest('hex')); + + write(path.join(directory, 'i18n/uk/docusaurus-plugin-content-docs/current/locale.md'), + localized.replace('WATERLINE_LOCALE=es', 'WATERLINE_LOCALE=uk')); + assert.throws(() => checkCodeBlocks(directory), + /Ukrainian executable examples differ from English: locale\.md/); + assert.equal(Object.keys(checkCodeBlocks(directory, ['de'])).length, 1); +}); diff --git a/scripts/check-doc-translations.js b/scripts/check-doc-translations.js index fd60617aedf..e7297f0b2ff 100644 --- a/scripts/check-doc-translations.js +++ b/scripts/check-doc-translations.js @@ -1,43 +1,23 @@ -const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); -const {createHash} = require('node:crypto'); -const {checkCurrentTranslations, checkTranslationUpdatesFromGit} = require('./check-doc-translation-updates'); +const { + locales, + localeLabels, + checkCodeBlocks, + checkCurrentTranslations, + checkTranslationUpdatesFromGit, +} = require('./check-doc-translation-updates'); const root = path.resolve(__dirname, '..'); const currentCount = checkCurrentTranslations(root); console.log(`All seven other locales contain ${currentCount} current guides with current reviewed-source hashes.`); checkTranslationUpdatesFromGit(root); -const locales = {es: 'Spanish', 'pt-BR': 'Brazilian Portuguese', 'zh-Hans': 'Simplified Chinese', ja: 'Japanese', fr: 'French', de: 'German'}; -function codeBlocks(file) { - const text = fs.readFileSync(file, 'utf8'); - return [...text.matchAll(/^```[^\n]*\n[\s\S]*?^```\s*$/gm)].map(match => match[0].trimEnd()); -} - -for (const [locale, label] of Object.entries(locales)) { - const translatedRoot = path.join(root, `i18n/${locale}/docusaurus-plugin-content-docs/current`); +const hashes = checkCodeBlocks(root); +for (const locale of locales) { + const label = localeLabels[locale]; + const currentHashes = hashes[locale]; const reviewFile = path.join(root, `i18n/${locale}/source-hashes.json`); - const currentHashes = {}; - let checked = 0; - function visit(directory) { - for (const entry of fs.readdirSync(directory, {withFileTypes: true})) { - const file = path.join(directory, entry.name); - if (entry.isDirectory()) { - visit(file); - } else if (/\.mdx?$/.test(entry.name)) { - const relative = path.relative(translatedRoot, file); - const source = path.join(root, 'docs', relative); - assert.deepEqual(codeBlocks(file), codeBlocks(source), - `${label} executable examples differ from English: ${relative}`); - currentHashes[relative] = createHash('sha256') - .update(fs.readFileSync(source)).digest('hex'); - checked += 1; - } - } - } - - visit(translatedRoot); if (process.argv.includes('--record-review')) { fs.writeFileSync(reviewFile, `${JSON.stringify(currentHashes, null, 2)}\n`); } else { @@ -48,5 +28,5 @@ for (const [locale, label] of Object.entries(locales)) { console.warn(`${label} translation review needed: ${changedSources.join(', ')}. See README.md.`); } } - console.log(`${label} code blocks match English in ${checked} guides.`); + console.log(`${label} code blocks match English in ${Object.keys(currentHashes).length} guides.`); }