1
votes

I want to learn how to build an opensource e-commerce site. For this purpose I'm using 'Django' framework with 'Oscar' extension.

I read the whole tutorial here: https://django-oscar.readthedocs.io/en/releases-1.5/index.html, where there is a Translation tutorial. I followed it (must say that it has missing steps). This part says that, in order to translate a page you must create two folders and a symbolic link:

mkdir locale i18n
ln -s $PATH_TO_OSCAR i18n/oscar

Then, for each language you want to translate:

./manage.py makemessages --symlinks --locale=<language code>

That's correct but, besides that, you must compile .po files in order to get the final traduction in locale folder (.mo files). After that you must include the traductions into settings.py of project (or app). This is done with the following code:

  • In terminal (from root directory of project): $ django-admin.py compilemessages
  • In settings.py add:

    LANGUAGES = [ ('de', _('German')), ('en', _('English')), ('es', _('Spanish')), ]

(Note: This is my case, where I want to translate the store into German, Spanish and English)

After doing that, I run my server and only these three languages appear in the select language box, but when I push the button in order to translate the page, It returns the default language (English) every time, getting this in each translation petition:

"POST /i18n/setlang/ HTTP/1.1" 302 0
"GET / HTTP/1.1" 200 8379

Is there any step I'm skipping or anything I'm doing wrong?

Thanks in advance.

1

1 Answers

2
votes

I've got a partial (almost complete) solution. Due to languages I want to use are very common, I used Django translation middleware directly, without using the one Oscar provides. So, my solution is to edit settings.py by including in MIDDLEWARE (or in MIDDLEWARE_CLASES depending of Django version) the Django internacionalization middleware: django.middleware.locale.LocaleMiddleware.

After that, without importing ugettext (from django.utils.translation import ugettext as _), feel free to add languages as follows:

LANGUAGES = [
    ('es', 'Spanish'),
    ('de', 'German'),
    ('en', 'English'),
    ('pt-br', 'Brazilian'),
    #... and so on
]

This solution doesn't need creating symbolic links or additional folders.