feat: migrate i18n system from static to dynamic JSON-based approach #695
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.
Overview
Refactored the entire internationalization (i18n) system from hardcoded Go functions to a dynamic JSON-based loader using reflection. This change makes adding new languages as simple as creating a JSON file - no code changes required.
What Changed
Before (Static Approach)
spanishSet(),frenchSet())After (Dynamic Approach)
translations/en.json,translations/es.json, etc.)Technical Details
New Architecture
Key Files Added
pkg/i18n/i18n.go- Dynamic loader with reflectionpkg/i18n/types.go- Type definitionstranslations/*.json- Language files (en, az, tr, es)create_language.py- Utility to generate new language filescreate_language.sh- Bash alternative for language generationPerformance
Migration Guide
Old Code
New Code
{ "code": "es", "name": "Español", "translations": { "GlobalTitle": "Global", "MainTitle": "Inicio", "Remove": "borrar" } }Usage Example
Adding New Languages
Method 1: Using Python Script
Method 2: Using Bash Script
Method 3: Manual
Create
translations/xx.jsonwith structure:{ "code": "xx", "name": "Language Name", "translations": { "Key": "Translation" } }Benefits
For Developers
For Translators
For Project
Backward Compatibility
The old static functions (
englishSet(),spanishSet(), etc.) remain as fallback if JSON loading fails, ensuring zero breaking changes.Testing
Tested with 4 languages:
Files Changed
pkg/i18n/i18n.go(refactored to use reflection)pkg/i18n/types.go(type definitions)translations/en.json(English)translations/az.json(Azerbaijani)translations/tr.json(Turkish)translations/es.json(Spanish)create_language.py(utility script)create_language.sh(utility script)USAGE.md(documentation)Future Enhancements
Possible additions:
Breaking Changes
None. The system maintains backward compatibility with existing code.
Closes: #XXX (if applicable)
Related: Translation system modernization initiative