Help with localization

2 views
Skip to first unread message

Martin Tiršel

unread,
Jul 25, 2010, 9:16:34 PM7/25/10
to Django users
Hello,

I can not get my translation working. Structure:

* minicms - CMS project
* userproject - project using minicms

- minicms
|-plugins
||-contactform
|||-locale
|||-templatetags
|||-forms.py

* forms.py:

# -*- coding: utf-8 -*-
from django import forms
from django.utils.translation import ugettext_lazy as _

class ContactForm(forms.Form):
name = forms.CharField(
label=_("Your name"),
help_text=_("Your name will be displayed"),
max_length=100
)
...

* locale/sk/LC_MESSAGES/django.po:
...
#: forms.py:7
msgid "Your name"
msgstr "Vaše meno"
...

* compiled into django.mo

* userproject/settings.py:
LANGUAGE_CODE = 'sk'

LANGUAGES = (
('en', 'English'),
('sk', 'Slovensky'),
)
USE_I18N = True
USE_L10N = True

Displayed form is in english. I tried to copy locale directory to all
possible places (minicms, minicms/plugins, userproject, ...) but
everything is only in english :(

Thanks,
Martin

Lachlan Musicman

unread,
Jul 25, 2010, 9:37:40 PM7/25/10
to django...@googlegroups.com
I have L10n working, and the set up is almost the same.

I also have, in settings.py the following:

LOCALE_PATH = (
    os.path.join(PROJECT_DIR, "myapp/locale"),
    )

 
* locale/sk/LC_MESSAGES/django.po:
...
#: forms.py:7
msgid "Your name"
msgstr "Vaše meno"
...


Confirm which version of Django you are using? Also, confirm that you are using 
django-admin.py makemessages -l sk to create the po file?

 
* compiled into django.mo

and django-admin.py compilemessages to make the mo file?


* userproject/settings.py:
LANGUAGE_CODE = 'sk'

LANGUAGES = (
   ('en', 'English'),
   ('sk', 'Slovensky'),
)
USE_I18N = True
USE_L10N = True

Displayed form is in english. I tried to copy locale directory to all possible places (minicms, minicms/plugins, userproject, ...) but everything is only in english :(


Also, when developing, I find that Chromium (on Ubuntu 10.4) for instance, ignores all the localisation for the computer install default, whereas Firefox will obey the lang setting (edit->prefs->content->languages). Which is handy, because I'm monolingual - I can work in Chromium and test in Firefox.

Try the settings.py:LOCALE_PATH first and let us know. If that doesn't work, make sure you answer the other questions posed above.

cheers
L.
 

Lachlan Simpson
Technology Manager
Translation and Interpreting Studies
Monash University, Clayton
Victoria 3800

Lachlan Musicman

unread,
Jul 25, 2010, 9:46:10 PM7/25/10
to django...@googlegroups.com

On Mon, Jul 26, 2010 at 11:16, Martin Tiršel <dja...@blackpage.eu> wrote:
* userproject/settings.py:
LANGUAGE_CODE = 'sk'

LANGUAGES = (
   ('en', 'English'),
   ('sk', 'Slovensky'),
)
USE_I18N = True
USE_L10N = True

Gah, my eyes were closed.

Have you also added the appropriate Middleware product?

As you see here: http://docs.djangoproject.com/en/dev/topics/i18n/deployment/#topics-i18n-deployment you need to have soemthing like the following:


MIDDLEWARE_CLASSES = (
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.locale.LocaleMiddleware',
   'django.middleware.common.CommonMiddleware',
)

remember that order is important - that doc page has more info


cheers
L.

Lachlan Simpson
Technology Manager
Translation and Interpreting Studies
Monash University, Clayton
Victoria 3800

Martin Tiršel

unread,
Jul 26, 2010, 7:53:19 AM7/26/10
to django...@googlegroups.com
On Mon, 26 Jul 2010 03:46:10 +0200, Lachlan Musicman <dat...@gmail.com>
wrote:

> On Mon, Jul 26, 2010 at 11:16, Martin Tiršel <dja...@blackpage.eu> wrote:
>
>
> Gah, my eyes were closed.
>
> Have you also added the appropriate Middleware product?
>
> As you see here:
> http://docs.djangoproject.com/en/dev/topics/i18n/deployment/#topics-i18n-deployment
> you
> need to have soemthing like the following:
>
> MIDDLEWARE_CLASSES = (
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.locale.LocaleMiddleware',
> 'django.middleware.common.CommonMiddleware',)
>
>
> remember that order is important - that doc page has more info

Hi,

yes, I have correct middlewares installed.

I printed some debug informations into template and LANGUAGE_CODE was set
to 'sk' (at this point I sure had somewhere a bug, possibly not compiled
translation I accidentaly deleted), but when I checked it now, there was
'en'. LocaleMiddleware takes the language code first from session, then
cookie, THEN Accept-Language from HTTP and if it all fails, then from
settings. But my browsers are set to 'en' and that was the "problem".

So, if I want to specify only single language in settings.py, I have to
REMOVE 'django.middleware.locale.LocaleMiddleware' from middlewares, else
settings.LANGUAGE_CODE is ignored (AFAIK today every browser sends
Accept-Language).

Martin

Reply all
Reply to author
Forward
0 new messages