# i18n Setup Verification Checklist

Complete this checklist to verify your internationalization setup is working correctly.

## ✅ Phase 1: Configuration

- [ ] **Settings Configured**
  ```python
  # nexusmart/settings.py
  USE_I18N = True
  LANGUAGE_CODE = "en"
  LANGUAGES = [10 language codes]
  LOCALE_PATHS = [BASE_DIR / 'locale']
  ```

- [ ] **Middleware Configured**
  ```python
  # nexusmart/settings.py MIDDLEWARE
  'django.middleware.locale.LocaleMiddleware'
  'shop.middleware.LanguageCurrencySyncMiddleware'
  ```

- [ ] **Context Processor Added**
  ```python
  # nexusmart/settings.py TEMPLATES context_processors
  'shop.context_processors.language_context'
  ```

- [ ] **Locale Directory Exists**
  ```
  locale/
  ├── de/LC_MESSAGES/
  ├── fr/LC_MESSAGES/
  ├── ...
  ```

---

## ✅ Phase 2: URL Configuration

- [ ] **i18n_patterns Used**
  - [ ] File: `nexusmart/urls.py`
  - [ ] Contains: `from django.conf.urls.i18n import i18n_patterns`
  - [ ] URLs wrapped: `i18n_patterns(prefix_default_language=True, ...)`
  - [ ] Result: URLs appear as `/en/products/`, `/de/products/`

**Test**:
```bash
python manage.py showurls | grep -i language
```

---

## ✅ Phase 3: Template Setup

- [ ] **Base Template Updated**
  - [ ] File: `templates/base.html`
  - [ ] Has: `{% load i18n %}`
  - [ ] Has: `<html lang="{{ LANGUAGE_CODE }}" dir="{% if LANGUAGE_BIDI %}rtl{% else %}ltr{% endif %}">`
  - [ ] Has: RTL CSS styles for `html[dir="rtl"]`

- [ ] **Major Templates Have i18n**
  - [ ] `templates/navbar.html` - ✓ Has `{% load i18n %}`
  - [ ] `templates/index.html` - ✓ Has `{% load i18n %}`
  - [ ] `templates/about.html` - ✓ Has `{% load i18n %}`
  - [ ] `templates/contact.html` - ✓ Has `{% load i18n %}`
  - [ ] `templates/faq.html` - ✓ Has `{% load i18n %}`
  - [ ] `templates/help.html` - ✓ Has `{% load i18n %}`
  - [ ] `shop/templates/shop/product_list.html` - ✓ Has `{% load i18n %}`
  - [ ] `shop/templates/shop/product_detail.html` - ✓ Has `{% load i18n %}`
  - [ ] `shop/templates/shop/cart.html` - ✓ Has `{% load i18n %}`
  - [ ] `shop/templates/shop/wishlist.html` - ✓ Has `{% load i18n %}`
  - [ ] `shop/templates/shop/checkout.html` - ✓ Has `{% load i18n %}`
  - [ ] `shop/templates/shop/create_product.html` - ✓ Has `{% load i18n %}`
  - [ ] `users/templates/accounts/user_dashboard.html` - ✓ Has `{% load i18n %}`
  - [ ] `users/templates/accounts/customer_profile.html` - ✓ Has `{% load i18n %}`
  - [ ] `users/templates/accounts/customer_form.html` - ✓ Has `{% load i18n %}`
  - [ ] `users/templates/address/shipping_address_form.html` - ✓ Has `{% load i18n %}`
  - [ ] `users/templates/address/shipping_address_list.html` - ✓ Has `{% load i18n %}`

**Test**:
```bash
grep -r "{% load i18n %}" templates/ shop/templates/ users/templates/
```

---

## ✅ Phase 4: Python String Translation

- [ ] **Views Have Translation Support**
  - [ ] File: `shop/views.py`
  - [ ] Contains: `from django.utils.translation import gettext_lazy as _`
  - [ ] Usage: `messages.success(request, _("Message text"))`

- [ ] **Admin Has Translation Support**
  - [ ] File: `shop/admin.py`
  - [ ] Contains: `from django.utils.translation import gettext_lazy as _`
  - [ ] Usage: 
    ```python
    site_header = _("BanshiMart Admin")
    site_title = _("BanshiMart Administration")
    index_title = _("Dashboard")
    ```

**Test**:
```python
# In Django shell
from shop import views
from django.utils.translation import get_language
print(get_language())  # Should return current language
```

---

## ✅ Phase 5: Context Processor

- [ ] **Context Processor Implemented**
  - [ ] File: `shop/context_processors.py`
  - [ ] Contains: `language_context()` function
  - [ ] Returns: `current_language`, `LANGUAGE_CODE`, `available_languages`, `language_currency_map`, `LANGUAGE_BIDI`

**Test in templates**:
```django
{{ LANGUAGE_CODE }}          {# Should show current language code #}
{{ LANGUAGE_BIDI }}          {# Should be True for RTL languages #}
{{ current_language }}       {# Should match LANGUAGE_CODE #}
{{ language_currency_map }}  {# Should show mapping #}
```

---

## ✅ Phase 6: Language Views

- [ ] **Language Switching View Exists**
  - [ ] File: `shop/language_views.py`
  - [ ] Has: `set_language_with_code()` function
  - [ ] Sets: `request.session['django_language']`
  - [ ] Saves: Language preference

- [ ] **URL Mapped**
  - [ ] File: `shop/urls.py`
  - [ ] Route: `path('set-language/<str:language_code>/', ...)`
  - [ ] Name: `'set_language_with_code'`

**Test**:
```bash
curl http://localhost:8000/shop/set-language/de/
# Should redirect and set language to German
```

---

## ✅ Phase 7: Translation Files

### Before Running makemessages:
- [ ] All translatable strings wrapped with `{% trans %}` or `_()`
- [ ] No hardcoded UI strings in templates
- [ ] All user-facing messages use translation

### Generate Translation Files:
```bash
cd c:\Users\Imokeuklemi\development_projects\nexusmart
python manage.py makemessages -a
```

- [ ] Files generated successfully
- [ ] Check: `locale/de/LC_MESSAGES/django.po` exists
- [ ] Check: `locale/fr/LC_MESSAGES/django.po` exists
- [ ] Check: 9 `.po` files created (one per non-English language)

**Verify**:
```bash
find locale -name "django.po" | wc -l
# Should output: 9
```

---

## ✅ Phase 8: Translation & Compilation

### Translate Strings:
- [ ] Open `locale/*/LC_MESSAGES/django.po` in Poedit or editor
- [ ] Translate strings for primary languages (de, fr, es, zh, ar)
- [ ] Mark uncertain translations with `#, fuzzy`
- [ ] Save `.po` files

### Compile Translations:
```bash
python manage.py compilemessages
```

- [ ] Compilation successful
- [ ] Check: `locale/de/LC_MESSAGES/django.mo` exists
- [ ] Check: 9 `.mo` files created

**Verify**:
```bash
find locale -name "django.mo" | wc -l
# Should output: 9
```

---

## ✅ Phase 9: Functional Tests

### Start Server:
```bash
python manage.py runserver
```

### Test English (en):
- [ ] Visit http://localhost:8000/en/
- [ ] All content displays in English
- [ ] Language selector shows "en" as active
- [ ] Currency shows in USD

### Test German (de):
- [ ] Visit http://localhost:8000/de/
- [ ] Language selector shows "de" as active
- [ ] Translated strings appear (if translated)
- [ ] Currency shows in EUR

### Test French (fr):
- [ ] Visit http://localhost:8000/fr/
- [ ] Language selector shows "fr" as active
- [ ] Any translated strings appear
- [ ] URL shows `/fr/`

### Test Language Switching:
- [ ] Click language dropdown in navbar
- [ ] Select different language
- [ ] Page refreshes in new language
- [ ] Session persists language preference

### Test RTL (Arabic):
- [ ] Visit http://localhost:8000/ar/
- [ ] Page direction is RTL
- [ ] Text aligns to right
- [ ] Cart drawer appears from left
- [ ] HTML `dir="rtl"` attribute set

**Verify in browser console**:
```javascript
document.documentElement.dir   // Should be "rtl" for Arabic
document.documentElement.lang  // Should be "ar"
```

### Test Currency Auto-Sync:
- [ ] Switch to German → Currency becomes EUR
- [ ] Switch to Chinese → Currency becomes CNY
- [ ] Switch to Japanese → Currency becomes JPY
- [ ] Switch to English → Currency becomes USD

---

## ✅ Phase 10: Advanced Features

### Pluralization (Optional):
- [ ] Templates handle plurals correctly
  ```django
  {% blocktrans count counter=items %}
    {{ counter }} item
  {% plural %}
    {{ counter }} items
  {% endblocktrans %}
  ```

### Context Hints (Optional):
- [ ] Context provided for ambiguous strings
  ```django
  {% trans "Order" context "verb" %}
  ```

### Database Translations (Optional):
- [ ] Evaluate if product descriptions need i18n
- [ ] Consider: django-modeltranslation or django-parler
- [ ] Implement if needed

---

## ✅ Phase 11: Performance

- [ ] `.mo` files are being used (not `.po`)
- [ ] Language switching is fast
- [ ] No slowdown with 10 languages
- [ ] Page load times acceptable

**Check**:
```bash
# .mo files should be used (smaller, compiled)
ls -la locale/*/LC_MESSAGES/
# django.mo should be significantly smaller than django.po
```

---

## ✅ Phase 12: Documentation & Maintenance

- [ ] `I18N_SETUP.md` created ✓
- [ ] `TRANSLATION_QUICKSTART.md` created ✓
- [ ] `TRANSLATION_STRINGS_REFERENCE.md` updated ✓
- [ ] This checklist completed ✓
- [ ] i18n_manager.py helper script available ✓

### Ongoing Maintenance:
- [ ] Team knows how to add translatable strings
- [ ] Team knows how to regenerate `.po` files
- [ ] Team knows deployment procedure
- [ ] Regular updates to translation files

---

## 🚀 Deployment Checklist

Before deploying to production:

- [ ] All `.po` files translated (at least primary languages)
- [ ] All `.mo` files compiled
- [ ] Both `.po` and `.mo` files committed to git
- [ ] Locale directory includes all 9 languages
- [ ] Settings.py has `USE_I18N = True`
- [ ] LocaleMiddleware enabled
- [ ] Server configured for correct locale paths
- [ ] Language selector works on production server
- [ ] Each language accessible via URL prefix
- [ ] RTL works for Arabic on production
- [ ] Currency auto-syncs on production

---

## 🐛 Troubleshooting

### Strings Still in English
**Cause**: `.mo` files not compiled

**Fix**:
```bash
python manage.py compilemessages
python manage.py runserver
```

### Language Not Switching
**Cause**: Middleware not in correct order

**Fix**: Check `MIDDLEWARE` in settings.py:
```python
MIDDLEWARE = [
    ...
    'django.middleware.locale.LocaleMiddleware',  # Must be after SessionMiddleware
    'shop.middleware.LanguageCurrencySyncMiddleware',
    ...
]
```

### RTL Not Working
**Cause**: Missing LANGUAGE_BIDI in context

**Fix**: Verify context_processor is registered and returns `LANGUAGE_BIDI`

### Fuzzy Translations Showing
**Cause**: `.po` file has `#, fuzzy` marker

**Fix**: Remove `#, fuzzy` line or translate properly, then recompile

---

## Summary

| Component | Status | File |
|-----------|--------|------|
| Settings | ✅ | nexusmart/settings.py |
| Middleware | ✅ | nexusmart/settings.py |
| URLs | ✅ | nexusmart/urls.py |
| Templates | ✅ | All template files |
| Views | ✅ | shop/views.py |
| Admin | ✅ | shop/admin.py |
| Context | ✅ | shop/context_processors.py |
| Language Switching | ✅ | shop/language_views.py |
| Translation Files | ⏳ | locale/{lang}/LC_MESSAGES/ |
| Documentation | ✅ | .md files |

**Current Status**: ✅ Infrastructure Complete | ⏳ Translations Pending

Once you complete **Phase 7-8** (Translation Files & Compilation), your website will be fully multilingual!

---

**Last Updated**: 2024
**Next Step**: Run `python manage.py makemessages -a`
