# JSON-Based Translation System for Kobelly ## πŸŽ‰ Benefits of This System βœ… **No compilation needed** - Just edit JSON files directly βœ… **Edit English without breaking translations** - Each language is independent βœ… **Simple and lightweight** - No complex dependencies βœ… **Real-time updates** - Changes appear immediately after restart βœ… **Easy to maintain** - Clear JSON structure ## πŸ“ File Structure ``` translations/ β”œβ”€β”€ en.json # English translations β”œβ”€β”€ de.json # German translations β”œβ”€β”€ fr.json # French translations └── nl.json # Dutch translations ``` ## πŸ”§ How to Use ### 1. In Templates Replace Babel syntax with the new system: **Old (Babel):** ```html

{{ _('Welcome to Kobelly Web Solutions') }}

{{ _('We create stunning, modern websites') }}

``` **New (JSON-based):** ```html

{{ translate('Welcome to Kobelly Web Solutions') }}

{{ translate('We create stunning, modern websites') }}

{{ t('Welcome to Kobelly Web Solutions') }}

{{ t('We create stunning, modern websites') }}

``` ### 2. Adding New Translations 1. **Add the string to your template:** ```html

{{ t('New Section Title') }}

``` 2. **Add it to the translation files:** ```json // translations/en.json { "New Section Title": "New Section Title" } // translations/de.json { "New Section Title": "Neuer Abschnittstitel" } ``` 3. **Restart your Flask app** - Changes appear immediately! ### 3. Language Switching The system automatically detects language from: - URL parameter: `?lang=de` - Session storage - Browser preferences **Manual language switching:** ```html English Deutsch FranΓ§ais Nederlands ``` **Or use the built-in selector:** ```html {{ create_language_selector() | safe }} ``` ## πŸ› οΈ Management Scripts ### Extract New Strings ```bash python extract_translations.py ``` ### Clean Translation Files ```bash python clean_translations.py ``` ### Add New Language 1. Add language code to `SUPPORTED_LANGUAGES` in `translation_manager.py` 2. Create `translations/[lang].json` 3. Add translations ## πŸ“ Example Translation File ```json { "Home": "Home", "Services": "Services", "About": "About", "Contact": "Contact", "Welcome to Kobelly Web Solutions": "Welcome to Kobelly Web Solutions", "We create stunning, modern websites that drive results": "We create stunning, modern websites that drive results" } ``` ## πŸ”„ Migration from Babel 1. **Replace template syntax:** - `{{ _('text') }}` β†’ `{{ t('text') }}` - `{{ gettext('text') }}` β†’ `{{ translate('text') }}` 2. **Remove Babel dependencies:** - Remove `Flask-Babel` from requirements.txt - Remove `babel.cfg` 3. **Update app.py:** - Remove Babel imports and configuration - Add translation manager imports ## πŸš€ Getting Started 1. **Start the app:** ```bash python app.py ``` 2. **Edit translations:** - Open `translations/[language].json` - Replace English text with translations - Save and restart app 3. **Test language switching:** - Visit `http://localhost:5000?lang=de` - Or use the language selector ## πŸ’‘ Tips - **Keep keys descriptive** - Use full sentences as keys - **Use consistent naming** - Follow the same pattern for similar content - **Test all languages** - Make sure translations fit in your layout - **Backup your translations** - JSON files are easy to version control ## πŸ”§ Troubleshooting **Translations not showing?** - Check that the key exists in the JSON file - Restart the Flask application - Check browser console for errors **Language not switching?** - Clear browser cache - Check session storage - Verify language code is in `SUPPORTED_LANGUAGES` **New strings not appearing?** - Run `python extract_translations.py` to extract new strings - Add translations to all language files - Restart the application