Translation System Implementation Guide
Overview
This guide explains how to use the translation system to replace hardcoded French text in agent.py.Translation System Components
- translations.json - Contains all translations organized by context
- translations.py - Translation manager and helper functions
- t_customer() - Helper function to get translations with customer language preference
Usage Examples
1. Simple Translation (with access to payload and store_info)
2. Translation with Parameters
3. When payload/store_info not available
For methods that don’t have direct access to payload or store_info, you’ll need to:- Pass language as a parameter to the method:
- Use the translation with passed language:
Remaining Hardcoded Text to Replace
Payment Messages
- Line 1751: “Votre commande est prête pour le paiement.”
- Line 1767: “Vous allez être redirigé vers Twint…”
- Line 1770: “Vous allez être redirigé vers Revolut…”
- Line 1773: “Cliquez sur le lien ci-dessous pour procéder au paiement sécurisé par carte.”
Order Messages
- Line 1822: “⚠️ Certains détails de votre commande ont changé :\n”
- Line 1824: “\n\nVoici le résumé mis à jour de votre commande :”
- Line 2572: “Résumé de commande :\n ```”
- Line 2591: “Aucun article dans la commande, veuillez faire un choix.”
Delivery Messages
- Line 2704: “Livraison prévue ”
- Line 2711: “À récupérer en magasin ”
- Line 2720: “Commande au nom de ”
- Line 2723: “Notes de livraison : ”
- Line 2727: “Notes générale : ”
- Line 2783: “Frais de livraison : “
Button Labels
- Line 1842: “Je confirme ✅”
- Line 1846: “Payer autrement 💰”
- Line 3946: “Je confirme ✅”
- Line 3980: “Payer ✅”
- Line 3984: “Changer de carte 🔄”
- Line 3988: “Payer autrement 💰“
Delivery Status Messages
- Line 5247: “Votre commande est en attente d’un livreur.”
- Line 5250: “Un livreur a été assigné à votre commande! 🛵”
- Line 5254: “Code de livraison: ”
- Line 5257: “Votre livreur arrive au restaurant…”
- Line 5262: “Votre commande est en route! 🛵”
- Line 5276: “Votre commande a été livrée! Bon appétit! 😋“
Step-by-Step Process
- Identify the context - Determine where in the code the hardcoded text appears
- Check available variables - See if payload and store_info are available
- Get language preference - Use
_get_customer_language()if possible - Replace with translation - Use
t_customer()with appropriate key - Test - Ensure the translation works correctly
Adding New Translations
- Add to translations.json:
- Use in code:
Best Practices
- Always provide fallback - Use default_language parameter
- Group related translations - Keep translations organized by context
- Include descriptions - Document where each translation is used
- Test all languages - Ensure translations work for all supported languages
- Handle missing translations gracefully - The system returns the key if translation not found