installation-wide fixed language

6 views
Skip to first unread message

omat * gezgin.com

unread,
Feb 26, 2007, 8:14:11 AM2/26/07
to Django users
I want to have only one translation, the one set by the LANGUAGE_CODE
parameter to be available, no matter the browser settings. Django
checks the http header for accepted languages before the LANGUAGE_CODE
in the settings. Thus, I get the translation I want only when the
language is added to my browsers list of preferred languages.

But the browsers' language settings can be misleading in some cases.

I thought restricting the LANGUAGES will do, and add the following
lines to my settings, as suggested in the documentation:

gettext_noop = lambda s: s
LANGUAGES = (
('tr', gettext_noop('Turkish')),
)

but this doesn't solve the issue. Now I cannot get the translation
even when 'Turkish' is added to my browsers list of accepted
languages.

Thanks for any suggestions...
oMat

Baurzhan Ismagulov

unread,
Feb 26, 2007, 8:26:30 AM2/26/07
to django...@googlegroups.com
Hello omat,

On Mon, Feb 26, 2007 at 01:14:11PM -0000, omat * gezgin.com wrote:
> but this doesn't solve the issue. Now I cannot get the translation
> even when 'Turkish' is added to my browsers list of accepted
> languages.

1. Which version of Django?

2. Where are you trying to see the translation? Admin, or your
application?

With kind regards,
--
Baurzhan Ismagulov
http://www.kz-easy.com/

omat * gezgin.com

unread,
Feb 26, 2007, 8:57:26 AM2/26/07
to Django users
> 1. Which version of Django?

revision 4608 form svn

> 2. Where are you trying to see the translation? Admin, or your
> application?

my application


Thanks...

Baurzhan Ismagulov

unread,
Feb 26, 2007, 9:04:20 AM2/26/07
to django...@googlegroups.com
On Mon, Feb 26, 2007 at 01:57:26PM -0000, omat * gezgin.com wrote:
> > 2. Where are you trying to see the translation? Admin, or your
> > application?
>
> my application

Do I understand correctly that you want to have your application in
Turkish only? If so, what is the problem with writing all texts in
Turkish and not using the i18n infrastructure at all?

omat * gezgin.com

unread,
Feb 26, 2007, 9:24:11 AM2/26/07
to Django users
Yes, but I want the application to be internationalized. I want only
one of the installations to have only one translation.

This is a generic application to handle user registration tasks and I
want to use it on other installations which will be requiring
internationalization.

Another thing, I don't want to hard code messages like form validation
errors.


Thanks,
oMat

Ivan Sagalaev

unread,
Feb 26, 2007, 9:30:41 AM2/26/07
to django...@googlegroups.com
omat * gezgin.com wrote:
> Yes, but I want the application to be internationalized. I want only
> one of the installations to have only one translation.

I had this problem on my site. I don't know if it's a bug or not but I
managed to make it work by choosing English as a default language and
Russian (in my case) as a translation. As I understand, with gettext you
can't have exactly one language because it has separate concepts of a
default language and translations.

omat * gezgin.com

unread,
Feb 26, 2007, 11:00:50 AM2/26/07
to Django users
Ivan, I went through the python gettext documentation but I couldn't
find any distinction between a 'default language' and a translation.
It seems to work as a replacement tool that runs with a lookup table
which is the translation file.

To me, It sounds like a bug on Django side.

How did you solve your problem? Did you define the languages in the
setting file like:

LANGUAGES = (
('ru', 'Russian'),
('en', 'English'),
)

Does the order matter?


oMat

Baurzhan Ismagulov

unread,
Feb 26, 2007, 4:51:25 PM2/26/07
to django...@googlegroups.com
On Mon, Feb 26, 2007 at 02:24:11PM -0000, omat * gezgin.com wrote:
> Yes, but I want the application to be internationalized. I want only
> one of the installations to have only one translation.

I haven't tested this, but it seems that you need to list both 'en' and
'tr' in LANGUAGES and set LANGUAGE_CODE to 'tr'. If all mechanisms in
django/utils/translation/trans_real.py:get_language_from_request fail,
the user should get Turkish.

omat * gezgin.com

unread,
Feb 26, 2007, 5:52:49 PM2/26/07
to Django users
But I do not want the browser settings (ie the http accepted-headers)
or other options to be considered. I just want to have one preset
language for a specific installation.

I feel like limiting the language options with overriding the
LANGUAGES list should do, but I couldn't.

If there is a way to override the precedence of language
determination, this will also do, but I don't think there is.

Thanks,
oMat

Baurzhan Ismagulov

unread,
Feb 26, 2007, 7:11:13 PM2/26/07
to django...@googlegroups.com
On Mon, Feb 26, 2007 at 02:52:49PM -0800, omat * gezgin.com wrote:
> But I do not want the browser settings (ie the http accepted-headers)
> or other options to be considered. I just want to have one preset
> language for a specific installation.

* Write messages in Turkish and provide an English translation for the
projects that need it, but not for this one (untested).

* Hack this specific django installation to always return LANGUAGE_CODE
in get_language_from_request. I've tested this, it works. A better way
would be to use smth. like FORCE_LANGUAGE if set, otherwise fall back
to the stuff django does now. Then you can use the same django
installation for different projects.

omat * gezgin.com

unread,
Feb 27, 2007, 1:52:22 AM2/27/07
to Django users
Thanks for the suggestions.

> * Write messages in Turkish and provide an English translation for the
> projects that need it, but not for this one (untested).

This would be an interesting hack but there already exists a Turkish
translation. Reversing it would be a burden. Also, it wouldn't solve
the case for preset messages like form validation error messages.


> * Hack this specific django installation to always return LANGUAGE_CODE
> in get_language_from_request. I've tested this, it works. A better way

Maintenance nightmares


> would be to use smth. like FORCE_LANGUAGE if set, otherwise fall back
> to the stuff django does now. Then you can use the same django
> installation for different projects.

I agree. It would be great to have an option in the settings file. I
posted thşs suggestion in the on-going discussion on the upcoming
django release:

http://groups.google.com/group/django-users/browse_thread/thread/287912177d469a64


Thanks,
oMat

Reply all
Reply to author
Forward
0 new messages