# 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