forked from SuperKali/armbian-imager
-
-
Notifications
You must be signed in to change notification settings - Fork 5
i18n: Add AI-powered translation sync with OpenAI #45
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
Merged
+739
−0
Conversation
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
Adds automated translation file synchronization with AI-powered
translations using LibreTranslate API.
Features:
- Auto-detects missing translation keys from en.json source
- Translates new keys using LibreTranslate (free/public API)
- Preserves i18next placeholders like {{count}} and {{boardName}}
- Batch processing with rate limiting
- Falls back to TODO: prefix on translation failures
- GitHub Action runs daily and creates PRs automatically
- Supports custom LibreTranslate instances and API keys
Add push trigger to sync-locales workflow so translation files are automatically updated whenever changes are pushed to the branch.
Fix bug where localeFiles array contained language codes without .json extension, causing the script to attempt reading directories instead of files.
19d9b7b to
72f8950
Compare
Create partial Croatian translation file to test the auto-sync feature. Only includes translations for home, flash, modal, and device sections with missing keys to be filled by the sync script. Add hr (Croatian) to the LOCALE_CODE_MAP for automated translation.
Replace LibreTranslate with OpenAI API for higher quality translations. Benefits: - Much better translation quality with context-aware AI - Handles technical terminology appropriately - Better placeholder preservation - Configurable model selection (gpt-4o-mini default) - Cost-effective with gpt-4o-mini - No rate limiting issues Changes: - Use OpenAI Chat Completions API - Add specialized system prompts for UI translation - Provide section/key context for each translation - Update workflow to use OPENAI_API_KEY secret - Update documentation with OpenAI setup instructions
- Remove exit code 1 when translations are made - The workflow already detects changes via git diff - Clean up unused 'placeholders' variable
Create a minimal Croatian locale with only basic translations to test the auto-sync feature.
- Change batch size from 10 to 1 request - Increase delay from 1s to 22s between requests - Add progress indicator for long-running translations - This respects OpenAI free tier limit of 3 requests/minute For faster translation, add a payment method to your OpenAI account to increase rate limits.
Add support for different rate limits based on OpenAI account tier: - Free tier: 1 request/22s (3 RPM limit) - Paid tier: 50 requests/1s (500 RPM limit) Changes: - Add OPENAI_TIER environment variable (free/paid) - Auto-adjust batch size and delays based on tier and model - Show which tier is being used with helpful tips - Update documentation with rate limit comparison table Users can now set OPENAI_TIER=paid for 20-50x faster translations after adding a payment method to their OpenAI account.
Add ability to retry translations that previously failed (marked with TODO:). Changes: - Add collectFailedTranslations() function to find TODO: keys - Add RETRY_FAILED environment variable (default: false) - Track and report retry statistics in summary - Update workflow and documentation with retry instructions Usage: RETRY_FAILED=true node scripts/sync-locales.js This is useful when: - Rate limits caused previous failures - API had temporary issues - After upgrading to paid tier for faster retries
Correct rate limits based on OpenAI's documented tiers: - Free tier: 5 RPM (12s delay) - was too conservative at 22s - Paid Tier 1-2: 200 RPM (300ms delay, batch of 50) - Paid Tier 3-5: 500 RPM (120ms delay, batch of 50) This makes free tier ~2x faster (20 min vs 37 min for 100 keys) and paid tier even faster with proper batching. Also updated documentation to show that even a small balance gets you Tier 1-2 with 40x speedup over free tier.
Your account has a strict 3 RPM limit on free tier. Updated to use 21 second delay between requests to stay safely under the limit. Free tier: ~35 min for 100 keys (at 3 RPM) Paid tier: ~1 min for 100 keys (at 200 RPM) - 65x faster Recommendation: Add just billing to get 65x speedup.
Only run on manual dispatch and daily schedule to avoid triggering on every push to the branch.
Remove the hr.json test file that was used for testing the sync feature. Clean up the supported languages list.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds automated translation file synchronization with AI-powered translations using OpenAI API.
Features
en.json(source of truth){{count}}and{{boardName}}TODO:prefix if translation failsConfiguration
The workflow uses OpenAI API with:
OPENAI_API_KEYsecret (required) - Get from platform.openai.comOPENAI_MODELvariable (optional, default:gpt-4o-mini)OPENAI_APIvariable (optional, default:https://api.openai.com/v1)Translation Quality
OpenAI provides excellent translations with:
Cost Estimation
Using
gpt-4o-mini(default):Very cost-effective for automated translation workflows.
Files Changed
.github/workflows/sync-locales.yml- GitHub Action workflow with OpenAI integrationscripts/sync-locales.js- AI translation sync script using OpenAI APIscripts/README.md- Complete documentation with setup instructionssrc/locales/hr.json- Croatian locale (partial, for testing)Testing
Added Croatian (hr) locale with partial translations to demonstrate the sync feature. When the workflow runs with an API key, it will automatically translate the missing 64 keys.