1
votes

I was wrote program with use Django 1.3/Google App Engine and find lack of support and strange behavior.

Prapration - Polish translation (could be important)

First of all the ungettext not support Polish directly see but django 1.3 support PO file tag Plural-Forms (many not English languages has multiple plurals) - I do such for Polish language - maybe same will be for Russian:

Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);

I put some examples as said before ungettext is useless since Polish has more plural forms than English I used it to extract msgId nothing more

# should be 0 kóz
ungettext(u'%s kóz', u'%s kozy', 0) % 0
# should be 1 koza
ungettext(u'%s kóz', u'%s kozy', 1) % 1
# should be 2 kozy
ungettext(u'%s kóz', u'%s kozy', 2) % 2
# should be 5 kóz
ungettext(u'%s kóz', u'%s kozy', 5) % 5

I was use makemessages.py and translate this with trick to get 3 plural forms not 2 like in English (Polish need 2-3 forms):

msgid "%s kóz"
msgid_plural "%s kozy"
msgstr[0] "%s 1 koza"
msgstr[1] "%s 2 kozy"
msgstr[2] "%s 5 kóz"

Strange behavior of Django (major question)

Now more tricks I do but not understand behavior:

I was set all variable for DJANGO correctly including (hope so) and:

LANGUAGE_CODE = 'pl' - all translation works but not Polish one I have two form not 3. msgid "%s kóz" msgid_plural "%s kozy" msgstr[0] "%s 1 koza" msgstr[1] "%s 2 kozy" msgstr[2] "%s 5 kóz"

LANGUAGE_CODE = 'en' - all translation works (pl, en-us, en-gb, de-de, ...)

LANGUAGE_CODE = 'xx' - all translation works (pl, en-us, en-gb, de-de, ...)

LANGUAGE_CODE = 'en-us' - all translation works (pl, en-us, en-gb, de-de, ...) but not en-us transaltion

Why I should set my language to INVALID 'xx' or other not existing translation to make it working in django it is strange for me? Could you help me how to do it correclty?

1

1 Answers

1
votes

That was trivial mistake:

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'pl'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Valid languages
LANGUAGES = (
  (u'pl', _('Polski')),
  (u'en-us', _('angielski - Stany Zjednoczone')),
  (u'en-gb', _('angielski - Wielka Brytania')),
  (u'de-de', _('niemiecki - Niemcy')),
)

LOCALE_PATHS = (
  os.path.join(__ROOT_PATH, 'conf', 'locale'),
)

Paths was defined after first use so django cannot build default translation - here is fix very trivial.

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'pl'

LOCALE_PATHS = (
  os.path.join(__ROOT_PATH, 'conf', 'locale'),
)

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# Valid languages
LANGUAGES = (
  (u'pl', _('Polski')),
  (u'en-us', _('angielski - Stany Zjednoczone')),
  (u'en-gb', _('angielski - Wielka Brytania')),
  (u'de-de', _('niemiecki - Niemcy')),
)

LANGUAGE_CODE = 'xx' is creating invalid translation container which will be never used and first use of valid setting with other language like pl gives such nice side effect :)