python - How to use django translation with GAE? -


i have following setup -

folders structure:

myapp   - conf     - locale       - ru         - lc_messages           - django.mo # contains "this title." translation           - django.po   - templates     - index.html   setting.py   main.py 

app.yaml:

... env_variables:  django_settings_module: 'settings'  handlers: ... - url: /locale/ # need this?   static_dir: templates/locale  libraries: - name: django   version: "1.5" 

settings.py:

use_i18n = true  languages = (     ('en', 'en'),     ('ru', 'ru'), )  language_code = 'ru' language_cookie_name = 'django_language'  secret_key = 'some-dummy-value'  middleware_classes = (   'django.middleware.locale.localemiddleware' )  locale_paths = (     '/locale',     '/templates/locale', ) 

index.html:

{% load i18n %} ... {% trans "this title." %} 

and main.py:

from google.appengine.ext.webapp import template ... translation.activate('ru') template_values = {} file_template = template.render('templates/index.html', template_values) self.response.out.write(file_template) 

but in result "this title." displayed in english. wrong setup (or files location)?

you locale_dirs absolute paths translations files , current setup telling django in root of file system.

try point django correct path:

project_path = os.path.dirname(os.path.abspath(__file__))  locale_paths = (     os.path.join(project_path, 'conf/locale'), ) 

edit:

i stumbled on repo has example of how gae work django i18n: https://github.com/googlearchive/appengine-i18n-sample-python

please let me know if helps

edit 2:

try moving languages below locale_paths in settings. , add middlewares listed here

and force django use language when rendering template use example

you can use tag tell languages django has available:

{% get_available_languages %} 

Comments