I18N not working

22 views
Skip to first unread message

Alex Jonsson

unread,
Nov 24, 2008, 8:10:02 PM11/24/08
to Django users
Hey guys,

I have some problems with the translations of my website. Locally, it
works flawlessly. But as soon as I run the project on my server, it
won't translate. I've translated the project per app, and I'm
wondering if it could have something to do with my PYTHONPATH? As of
now, my .htaccess file looks like this:

ServerName domain.com
DocumentRoot /home/user/django/mysite

SetEnv DJANGO_SETTINGS_MODULE mysite.settings
SetHandler mod_python
PythonHandler django.core.handlers.modpython
PythonPath "['/home/user/django/', '/home/user/django/mysite/'] +
sys.path"
PythonDebug On

I'm completely clueless on this one. Like I said - it works flawlessly
locally and it's the same code. I should add that everything else
works just fine - custom template tags, import of models, you name it.
I've tried to recompile the language files on the server as well, but
to no avail.

Any suggestions on what I should look for?

Thanks!

Thomas Guettler

unread,
Nov 25, 2008, 3:23:01 AM11/25/08
to django...@googlegroups.com
Alex Jonsson schrieb:

> Hey guys,
>
> I have some problems with the translations of my website. Locally, it
> works flawlessly. But as soon as I run the project on my server, it
> won't translate. I've translated the project per app.
Translation per app only works if you have the LocaleMiddleware installed.
Maybe this setting is different on your server?

Thomas

--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

Jarek Zgoda

unread,
Nov 25, 2008, 4:28:58 AM11/25/08
to django...@googlegroups.com
Wiadomość napisana w dniu 2008-11-25, o godz. 09:23, przez Thomas
Guettler:

>> I have some problems with the translations of my website. Locally, it
>> works flawlessly. But as soon as I run the project on my server, it
>> won't translate. I've translated the project per app.
> Translation per app only works if you have the LocaleMiddleware
> installed.
> Maybe this setting is different on your server?


I know the per-app translations work without this. Mine works equally
with LANGUAGE_CODE and USE_I18N only on systems with "C" and "pl_PL".
There is no need to use LocaleMiddleware if you do not want to change
translations (eg. depending on browser settings).

--
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R&D, Redefine
jarek...@redefine.pl

Thomas Guettler

unread,
Nov 25, 2008, 5:17:34 AM11/25/08
to django...@googlegroups.com
The last days I did my first i18n application and befor I read this:
http://docs.djangoproject.com/en/dev/topics/i18n/
{{{
Application message files are a bit complicated to discover -- they need
the LocaleMiddleware.
If you don't use the middleware, only the Django message files and
project message files will be processed.

}}}

I don't know if it is really need. But the documentation says so. Or I
read it to quickly and overlooked

something.

Thomas

Jarek Zgoda schrieb:


> I know the per-app translations work without this. Mine works equally
> with LANGUAGE_CODE and USE_I18N only on systems with "C" and "pl_PL".
> There is no need to use LocaleMiddleware if you do not want to change
> translations (eg. depending on browser settings).
>
>


--

Jarek Zgoda

unread,
Nov 25, 2008, 5:39:14 AM11/25/08
to django...@googlegroups.com
Wiadomość napisana w dniu 2008-11-25, o godz. 11:17, przez Thomas
Guettler:

> The last days I did my first i18n application and befor I read this:
> http://docs.djangoproject.com/en/dev/topics/i18n/
> {{{
> Application message files are a bit complicated to discover -- they
> need
> the LocaleMiddleware.
> If you don't use the middleware, only the Django message files and
> project message files will be processed.
>
> }}}
>
> I don't know if it is really need. But the documentation says so. Or I
> read it to quickly and overlooked


I thing something is wrong with docs then, because I'm speaking from
my practice. On my site I have few apps with per-app translations
(django-registration, django-confirmation and so on) and I have some
sitewide translations for my own code. The translation keys from 3rd
party apps appear in my own catalog but I left them untranslated there
(as they are already translated). If the things would work as
described, the strings from registration app would appear untranslated
because I do not have LocaleMiddleware installed. Of course, they
appear in Polish, as I expected.

Malcolm Tredinnick

unread,
Nov 25, 2008, 5:47:18 AM11/25/08
to django...@googlegroups.com

On Tue, 2008-11-25 at 11:39 +0100, Jarek Zgoda wrote:
> Wiadomość napisana w dniu 2008-11-25, o godz. 11:17, przez Thomas
> Guettler:
>
> > The last days I did my first i18n application and befor I read this:
> > http://docs.djangoproject.com/en/dev/topics/i18n/
> > {{{
> > Application message files are a bit complicated to discover -- they
> > need
> > the LocaleMiddleware.
> > If you don't use the middleware, only the Django message files and
> > project message files will be processed.
> >
> > }}}
> >
> > I don't know if it is really need. But the documentation says so. Or I
> > read it to quickly and overlooked
>
>
> I thing something is wrong with docs then, because I'm speaking from
> my practice.

That quoted section does seem to be inaccurate. The code that fetches
the translations is in django.util.translation.trans_real.translation()
and it always runs through settings.INSTALLED_APPS looking for locale
files.

I'm rewriting the i18n documentation at the moment, so I've made a note
to fix that confusion (that whole section is already basically just a
big FIXME at the moment anyway).

Regards,
Malcolm


Alex Jonsson

unread,
Nov 25, 2008, 6:01:58 AM11/25/08
to Django users
Thank you everyone for your feedback.

I forgot to mention that I read that paragraph in the docs as well and
already installed the LocaleMiddleware. This makes the translation of
the built-in modules work, but not my per-app translations. This was
why I was thinking that maybe it had something to do with my
PYTHONPATH. I've even tried to change it to include all the apps
directories, but that was to no avail either.

Any ideas?

On Nov 25, 11:47 am, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Alex Jonsson

unread,
Nov 25, 2008, 6:03:15 AM11/25/08
to Django users
Oh, and another note.

I have checked my browser language, it's set to Swedish. That works
locally as well with LocaleMiddleware.

Malcolm Tredinnick

unread,
Nov 25, 2008, 6:03:18 AM11/25/08
to django...@googlegroups.com

On Tue, 2008-11-25 at 03:01 -0800, Alex Jonsson wrote:
> Thank you everyone for your feedback.
>
> I forgot to mention that I read that paragraph in the docs as well and
> already installed the LocaleMiddleware. This makes the translation of
> the built-in modules work, but not my per-app translations. This was
> why I was thinking that maybe it had something to do with my
> PYTHONPATH. I've even tried to change it to include all the apps
> directories, but that was to no avail either.
>
> Any ideas?

Have you checked permissions? Does the webserver have permission to read
the files in question (including permission to access the directories
all the way the down to the files)?

Malcolm


Alex Jonsson

unread,
Nov 25, 2008, 6:37:09 AM11/25/08
to Django users
I did just check the permissions, and even tried change them to a=rwx.
Still not working.

I tried a couple of other things as well - I made a symlink in one of
my folders on my PYTHONPATH pointing to my project (it required me to
do that in order to run the django-admin.py makemessages command) and
then made and compiled a project-wide translation. Still not working!

Could it have something to do with gettext or such? I use the
ugettext_lazy and my server runs Python 2.3.

On Nov 25, 12:03 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:

Alex Jonsson

unread,
Nov 25, 2008, 8:54:41 AM11/25/08
to Django users
Woohoo! Looks like I solved it.

The error I had made was that inside my locale folders I had named
Swedish "sv_se" which wasn't right. I looked into the django/conf/
locale folder and saw that there they referred to Swedish as "sv". So
by changing the folder names Django finally found them.

Oh, and I can concur that the LocaleMiddleware is not needed to
translate per-app.

Thank you everyone for your help!
Reply all
Reply to author
Forward
0 new messages