Skip to content

Commit 341a23f

Browse files
committed
feat: enhance Crowdin spacing formatting
- Added a function to identify translated files, preventing formatting changes to localized content. - Updated the file processing logic to skip formatting for translated files and log the count of skipped files. - Removed specific file pattern from processing to streamline the formatting function.
1 parent 81a0210 commit 341a23f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/format-crowdin-spacing.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const colors = {
2626
const canonicalAdmonitionTypes = new Set(['note', 'tip', 'info', 'warning', 'caution', 'danger', 'important']);
2727
// Build a dynamic regex group from canonical types so we don't miss any
2828
const admonitionTypesGroup = Array.from(canonicalAdmonitionTypes).join('|');
29+
const TRANSLATION_ROOT = 'i18n';
30+
31+
function isTranslatedFile(filePath) {
32+
const relative = path.relative(TRANSLATION_ROOT, filePath);
33+
return relative && !relative.startsWith('..') && !path.isAbsolute(relative);
34+
}
2935

3036
const admonitionSynonyms = new Map([
3137
['nota', 'note'],
@@ -499,7 +505,6 @@ function formatCrowdinSpacing() {
499505
// Find all .mdx files
500506
const patterns = [
501507
'docs/**/*.{md,mdx}',
502-
'i18n/*/docusaurus-plugin-content-docs/**/*.{md,mdx}',
503508
];
504509

505510
const fileSet = new Set();
@@ -515,8 +520,15 @@ function formatCrowdinSpacing() {
515520
const files = Array.from(fileSet);
516521
let totalFixed = 0;
517522
const fixedFiles = [];
523+
const skippedTranslatedFiles = [];
518524

519525
files.forEach(file => {
526+
if (isTranslatedFile(file)) {
527+
const relativePath = path.relative(process.cwd(), file);
528+
skippedTranslatedFiles.push(relativePath);
529+
return;
530+
}
531+
520532
const originalContent = fs.readFileSync(file, 'utf8');
521533
const formattedContent = processContent(originalContent, file);
522534

@@ -539,6 +551,10 @@ function formatCrowdinSpacing() {
539551
console.log(`${colors.green}✅ All files already have proper spacing for Crowdin compatibility!${colors.reset}`);
540552
}
541553

554+
if (skippedTranslatedFiles.length > 0) {
555+
console.log(`\n${colors.blue}Skipped formatting for ${skippedTranslatedFiles.length} translated file${skippedTranslatedFiles.length === 1 ? '' : 's'} to preserve localized content.${colors.reset}`);
556+
}
557+
542558
return totalFixed;
543559
}
544560

0 commit comments

Comments
 (0)