
Django Internationalization
i18n, gettext, translation strings, locale middleware, language detection, translation files
1Which function should be used to mark a string as translatable in Django?
Which function should be used to mark a string as translatable in Django?
Risposta
The gettext function, commonly imported with the _ (underscore) alias, is the standard method for marking translatable strings in Django. It looks up the translation of the string in the message catalog corresponding to the active language and returns the translated version if available.
2What is the difference between gettext() and gettext_lazy() in Django?
What is the difference between gettext() and gettext_lazy() in Django?
Risposta
gettext_lazy() returns a proxy object that is only evaluated when converted to a string, which is essential for translations defined at module level (like in models or forms). gettext() immediately evaluates the translation at call time, which is problematic if the language isn't determined yet.
3Which Django middleware is responsible for activating the language for each request?
Which Django middleware is responsible for activating the language for each request?
Risposta
LocaleMiddleware examines the request to determine the user's preferred language by checking multiple sources: URL prefix, cookies, browser's Accept-Language header, and the LANGUAGE_CODE setting. It then activates the corresponding language for the entire request duration.
Which Django command extracts translatable strings from the source code?
Which command compiles .po translation files into binary .mo files?
+17 domande da colloquio
Altri argomenti di colloquio Django
Python Basics
Python OOP
Django Fundamentals
Django Models - Basics
Django Views
Django Templates
Django Forms
Advanced QuerySets
Django Authentication
Django Middleware
Django Admin
Django REST Framework
Django Signals
File Upload
Django Caching
Django Sessions
Django Email
Django Testing
Django Security
Django Deployment
Advanced Django ORM
Django Performance
Django & Celery
Django Channels
Django & GraphQL
Django & Docker
Django in Microservices Ecosystem
Custom Django Commands
Django Design Patterns
Django Async & ASGI
Settings & Production Configuration
Observability & Monitoring
Padroneggia Django per il tuo prossimo colloquio
Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.
Inizia gratis