Skip to content

Commit 334e24e

Browse files
fix(scripts): sort locale comparisons and update test locale expectations
Add locale sorting to duplicate and similar comparison arrays in docs and blog translation reports for deterministic output. Update test expectations to include the full set of 29 supported locales. Co-Authored-By: Hagicode <noreply@hagicode.com> Signed-off-by: newbe36524 <newbe36524@qq.com>
1 parent 7650950 commit 334e24e

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

scripts/report-blog-translation-status.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ function incrementLocaleIssue(localeIssues, localeCode, key) {
283283
entry[key] += 1;
284284
}
285285

286+
function compareByLocale(left, right) {
287+
return left.locale.localeCompare(right.locale);
288+
}
289+
286290
export async function generateBlogTranslationReport(options = {}) {
287291
const rootDirectory = path.resolve(options.contentRoot ?? defaultContentRoot);
288292
const projectRoot = inferProjectRoot(rootDirectory, options.projectRoot);
@@ -351,6 +355,9 @@ export async function generateBlogTranslationReport(options = {}) {
351355
incrementLocaleIssue(localeIssues, localeCode, 'similarSlugCount');
352356
}
353357

358+
duplicateComparisons.sort(compareByLocale);
359+
similarComparisons.sort(compareByLocale);
360+
354361
entries.push({
355362
slug,
356363
baselineLocale: BASELINE_LOCALE,

scripts/report-docs-translation-status.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ function incrementLocaleIssue(localeIssues, localeCode, key) {
342342
entry[key] += 1;
343343
}
344344

345+
function compareByLocale(left, right) {
346+
return left.locale.localeCompare(right.locale);
347+
}
348+
345349
export async function generateDocsTranslationReport(options = {}) {
346350
const rootDirectory = path.resolve(options.contentRoot ?? defaultContentRoot);
347351
const translationRoot = path.resolve(options.translationRoot ?? defaultTranslationRoot);
@@ -427,6 +431,9 @@ export async function generateDocsTranslationReport(options = {}) {
427431
}
428432
}
429433

434+
duplicateComparisons.sort(compareByLocale);
435+
similarComparisons.sort(compareByLocale);
436+
430437
entries.push({
431438
docKey: baselineDoc.docKey,
432439
baselineLocale: BASELINE_LOCALE,

tests/docs-translation-report.test.mjs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,27 @@ test('reports highly similar docs against zh-CN baseline and writes a JSON repor
139139

140140
test('covers the full configured locale set including zh-CN baseline', async () => {
141141
const expectedLocales = [
142-
'zh-CN', 'zh-Hant', 'en-US', 'ja-JP', 'ko-KR',
143-
'de-DE', 'fr-FR', 'es-ES', 'pt-BR', 'ru-RU',
142+
'zh-CN', 'en-US', 'zh-Hant', 'fr-FR', 'it-IT',
143+
'de-DE', 'es-ES', 'bg-BG', 'cs-CZ', 'da-DK',
144+
'nl-NL', 'fi-FI', 'el-GR', 'hu-HU', 'id-ID',
145+
'ja-JP', 'ko-KR', 'nb-NO', 'pl-PL', 'pt-BR',
146+
'pt-PT', 'ro-RO', 'ru-RU', 'es-419', 'sv-SE',
147+
'th-TH', 'tr-TR', 'uk-UA', 'vi-VN',
144148
];
145149
const actualCodes = REQUIRED_DOCS_LOCALES.map((locale) => locale.code);
146150
assert.deepEqual(actualCodes, expectedLocales);
147151

148-
const contentDirectories = REQUIRED_DOCS_LOCALES.filter((locale) => locale.contentDirectory).map((locale) => locale.contentDirectory);
149-
const expectedDirectories = ['zh-Hant', 'en-US', 'ja-JP', 'ko-KR', 'de-DE', 'fr-FR', 'es-ES', 'pt-BR', 'ru-RU'];
152+
const contentDirectories = REQUIRED_DOCS_LOCALES
153+
.filter((locale) => locale.contentDirectory)
154+
.map((locale) => locale.contentDirectory);
155+
const expectedDirectories = [
156+
'en-US', 'zh-Hant', 'fr-FR', 'it-IT', 'de-DE',
157+
'es-ES', 'bg-BG', 'cs-CZ', 'da-DK', 'nl-NL',
158+
'fi-FI', 'el-GR', 'hu-HU', 'id-ID', 'ja-JP',
159+
'ko-KR', 'nb-NO', 'pl-PL', 'pt-BR', 'pt-PT',
160+
'ro-RO', 'ru-RU', 'es-419', 'sv-SE', 'th-TH',
161+
'tr-TR', 'uk-UA', 'vi-VN',
162+
];
150163
assert.deepEqual(contentDirectories, expectedDirectories);
151164
});
152165

0 commit comments

Comments
 (0)