-
Notifications
You must be signed in to change notification settings - Fork 166
p5.js Reference Translation Automation Task #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Divyansh013
wants to merge
7
commits into
processing:main
Choose a base branch
from
Divyansh013:translation-github-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
46edaf0
Test: Add documentation line to circle.mdx for translation tracker te…
Divyansh013 ba9b4ee
Add Week 1 translation tracker implementation
Divyansh013 cd94f24
Test: Modify triangle.mdx for translation testing
Divyansh013 ddebbf3
Test: Modify accelerationX.mdx to test missing translation detection
Divyansh013 1e13287
removed testing logs
Divyansh013 875a77c
small fix
Divyansh013 5170eb6
post review changes
Divyansh013 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
const { execSync } = require('child_process'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
|
||
const SUPPORTED_LANGUAGES = ['es', 'hi', 'ko', 'zh-Hans']; | ||
const REFERENCE_PATH = 'src/content/reference'; | ||
const ENGLISH_PATH = path.join(REFERENCE_PATH, 'en'); | ||
Divyansh013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
function getChangedFiles() { | ||
try { | ||
|
||
|
||
|
||
const gitCommand = process.env.GITHUB_EVENT_NAME === 'pull_request' | ||
Divyansh013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? 'git diff --name-only HEAD~1 HEAD' | ||
: 'git diff --name-only HEAD~1 HEAD'; | ||
|
||
const changedFilesOutput = execSync(gitCommand, { encoding: 'utf8' }); | ||
const allChangedFiles = changedFilesOutput.trim().split('\n').filter(file => file.length > 0); | ||
|
||
|
||
const changedEnglishFiles = allChangedFiles.filter(file => | ||
file.startsWith(ENGLISH_PATH) && file.endsWith('.mdx') | ||
); | ||
|
||
console.log(` Total changed files: ${allChangedFiles.length}`); | ||
console.log(` Changed English reference files: ${changedEnglishFiles.length}`); | ||
|
||
if (changedEnglishFiles.length > 0) { | ||
console.log('📄 Changed English files:'); | ||
changedEnglishFiles.forEach(file => console.log(` - ${file}`)); | ||
} | ||
|
||
return changedEnglishFiles; | ||
} catch (error) { | ||
console.error(' Error getting changed files:', error.message); | ||
return []; | ||
} | ||
} | ||
|
||
|
||
function getTranslationPath(englishFilePath, language) { | ||
Divyansh013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return englishFilePath.replace('/en/', `/${language}/`); | ||
} | ||
|
||
/** | ||
* Check if a file exists | ||
*/ | ||
function fileExists(filePath) { | ||
try { | ||
return fs.existsSync(filePath); | ||
} catch (error) { | ||
return false; | ||
} | ||
} | ||
|
||
|
||
function getFileModTime(filePath) { | ||
try { | ||
return fs.statSync(filePath).mtime; | ||
} catch (error) { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
function checkTranslationStatus(changedEnglishFiles) { | ||
|
||
|
||
const translationStatus = { | ||
needsUpdate: [], | ||
missing: [], | ||
upToDate: [] | ||
}; | ||
|
||
changedEnglishFiles.forEach(englishFile => { | ||
|
||
|
||
const englishModTime = getFileModTime(englishFile); | ||
if (!englishModTime) { | ||
console.log(`Could not get modification time for English file`); | ||
return; | ||
} | ||
|
||
SUPPORTED_LANGUAGES.forEach(language => { | ||
const translationPath = getTranslationPath(englishFile, language); | ||
const exists = fileExists(translationPath); | ||
|
||
if (!exists) { | ||
console.log(` ❌ ${language}: Missing translation`); | ||
translationStatus.missing.push({ | ||
englishFile, | ||
language, | ||
translationPath, | ||
status: 'missing' | ||
}); | ||
} else { | ||
const translationModTime = getFileModTime(translationPath); | ||
const isOutdated = translationModTime < englishModTime; | ||
|
||
if (isOutdated) { | ||
console.log(` 🔄 ${language}: Needs update (English: ${englishModTime.toISOString()}, Translation: ${translationModTime.toISOString()})`); | ||
translationStatus.needsUpdate.push({ | ||
englishFile, | ||
language, | ||
translationPath, | ||
status: 'outdated', | ||
englishModTime, | ||
translationModTime | ||
}); | ||
} else { | ||
console.log(` ✅ ${language}: Up to date`); | ||
translationStatus.upToDate.push({ | ||
englishFile, | ||
language, | ||
translationPath, | ||
status: 'up-to-date' | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
return translationStatus; | ||
} | ||
|
||
|
||
function displaySummary(translationStatus) { | ||
console.log('\n📊 TRANSLATION STATUS SUMMARY'); | ||
console.log('═══════════════════════════════'); | ||
|
||
console.log(`🆕 Missing translations: ${translationStatus.missing.length}`); | ||
if (translationStatus.missing.length > 0) { | ||
translationStatus.missing.forEach(item => { | ||
console.log(` - ${item.language}: ${item.englishFile}`); | ||
}); | ||
} | ||
|
||
console.log(`🔄 Outdated translations: ${translationStatus.needsUpdate.length}`); | ||
if (translationStatus.needsUpdate.length > 0) { | ||
translationStatus.needsUpdate.forEach(item => { | ||
console.log(` - ${item.language}: ${item.englishFile}`); | ||
}); | ||
} | ||
|
||
console.log(`✅ Up-to-date translations: ${translationStatus.upToDate.length}`); | ||
|
||
console.log('\n💡 Next steps for Week 2+:'); | ||
|
||
|
||
function exploreRepoStructure() { | ||
console.log('\n🔍 REPOSITORY STRUCTURE ANALYSIS'); | ||
console.log('═══════════════════════════════════'); | ||
|
||
try { | ||
const referencePath = REFERENCE_PATH; | ||
console.log(`📁 Reference path: ${referencePath}`); | ||
|
||
if (fs.existsSync(referencePath)) { | ||
const languages = fs.readdirSync(referencePath) | ||
.filter(item => fs.statSync(path.join(referencePath, item)).isDirectory()) | ||
.filter(item => !item.startsWith('.')); | ||
|
||
console.log(`🌐 Available languages: ${languages.join(', ')}`); | ||
Divyansh013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Count files in each language | ||
languages.forEach(lang => { | ||
const langPath = path.join(referencePath, lang); | ||
try { | ||
const subdirs = fs.readdirSync(langPath) | ||
.filter(item => fs.statSync(path.join(langPath, item)).isDirectory()); | ||
|
||
let totalFiles = 0; | ||
subdirs.forEach(subdir => { | ||
const subdirPath = path.join(langPath, subdir); | ||
const files = fs.readdirSync(subdirPath) | ||
.filter(file => file.endsWith('.mdx')); | ||
totalFiles += files.length; | ||
}); | ||
|
||
console.log(` ${lang}: ${totalFiles} files across ${subdirs.length} categories`); | ||
} catch (error) { | ||
console.log(` ${lang}: Error reading directory - ${error.message}`); | ||
} | ||
}); | ||
} else { | ||
console.log(` Reference path does not exist: ${referencePath}`); | ||
} | ||
} catch (error) { | ||
console.error(' Error exploring repository structure:', error.message); | ||
} | ||
} | ||
|
||
|
||
function main() { | ||
console.log('p5.js Translation Sync Tracker - Week 1 Prototype'); | ||
console.log('════════════════════════════════════════════════════'); | ||
console.log(`📅 Event: ${process.env.GITHUB_EVENT_NAME || 'local'}`); | ||
console.log(`🏠 Working directory: ${process.cwd()}`); | ||
console.log(`🎯 Tracking languages: ${SUPPORTED_LANGUAGES.join(', ')}`); | ||
|
||
|
||
exploreRepoStructure(); | ||
|
||
|
||
const changedEnglishFiles = getChangedFiles(); | ||
|
||
if (changedEnglishFiles.length === 0) { | ||
console.log(' No changes detected in English reference files.'); | ||
console.log(' Nothing to track for translations in this commit!'); | ||
return; | ||
} | ||
|
||
|
||
const translationStatus = checkTranslationStatus(changedEnglishFiles); | ||
|
||
|
||
displaySummary(translationStatus); | ||
|
||
|
||
} | ||
|
||
// Run the main function | ||
if (require.main === module) { | ||
main(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "p5js-translation-tracker", | ||
"version": "1.0.0", | ||
Divyansh013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"description": "GitHub Action to track translation status for p5.js reference documentation", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node index.js", | ||
"test": "node index.js" | ||
}, | ||
"keywords": [ | ||
"p5.js", | ||
"translation", | ||
"documentation", | ||
"github-actions", | ||
"automation" | ||
], | ||
"author": "Divyansh Srivastava", | ||
"license": "LGPL-2.1", | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"dependencies": { | ||
"@actions/core": "^1.10.0", | ||
"@actions/github": "^5.1.1" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Local test script for the translation tracker | ||
* This simulates the GitHub Action environment for testing | ||
*/ | ||
|
||
const { execSync } = require('child_process'); | ||
const path = require('path'); | ||
|
||
process.env.GITHUB_EVENT_NAME = 'push'; | ||
process.env.GITHUB_WORKSPACE = process.cwd(); | ||
|
||
console.log('🧪 LOCAL TEST: Translation Tracker'); | ||
console.log('═══════════════════════════════════'); | ||
console.log(`📁 Working directory: ${process.cwd()}`); | ||
|
||
// Navigate to repository root | ||
const repoRoot = path.resolve(__dirname, '../../..'); | ||
process.chdir(repoRoot); | ||
|
||
console.log(`📁 Changed to repository root: ${process.cwd()}`); | ||
|
||
try { | ||
const gitLogOutput = execSync('git log --oneline -5', { encoding: 'utf8' }); | ||
console.log(' Recent commits:'); | ||
console.log(gitLogOutput); | ||
} catch (error) { | ||
console.log(' No git history available or not in a git repository'); | ||
} | ||
|
||
console.log(' Running translation tracker...\n'); | ||
|
||
try { | ||
require('./index.js'); | ||
} catch (error) { | ||
console.error('❌ Error running translation tracker:', error.message); | ||
console.error(error.stack); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Translation Sync Tracker | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
paths: | ||
- 'src/content/reference/en/**' | ||
pull_request: | ||
branches: [main] | ||
paths: | ||
- 'src/content/reference/en/**' | ||
|
||
jobs: | ||
track-translation-changes: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 # Fetch previous commit to compare changes | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
|
||
- name: Run translation tracker | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: node .github/actions/translation-tracker/index.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.