I was wrote program with use Django 1.3/Google App Engine and find lack of support and strange behavior.
我使用Django 1.3 / Google App Engine编写程序,发现缺乏支持和奇怪的行为。
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:
首先,ungettext不支持波兰语直接看到,但django 1.3支持PO文件标签多种形式(许多不是英语有多个复数) - 我这样做波兰语 - 也许是俄语:
Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);
多种形式:nplurals = 3;复数=(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
我把一些例子说成uncutext之前说的是没用的,因为波兰语有比英语更多的复数形式我用它来提取msgId而已
# 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):
我使用makemessages.py并用技巧翻译这个以获得3个复数形式而不是2个像英语(波兰语需要2-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"
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:
我正确设置了DJANGO的所有变量,包括(希望如此)和:
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 ='pl' - 所有翻译都有效,但不是波兰语我有两种形式而不是3. msgstr“%skóz”msgid_plural“%s kozy”msgstr [0]“%s 1 koza”msgstr [1]“%s 2 kozy“msgstr [2]”%s5kóz“
LANGUAGE_CODE = 'en' - all translation works (pl, en-us, en-gb, de-de, ...)
LANGUAGE_CODE ='en' - 所有翻译工作(pl,en-us,en-gb,de-de,...)
LANGUAGE_CODE = 'xx' - all translation works (pl, en-us, en-gb, de-de, ...)
LANGUAGE_CODE ='xx' - 所有翻译工作(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
LANGUAGE_CODE ='en-us' - 所有翻译作品(pl,en-us,en-gb,de-de,...)但不是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?
为什么我应该将我的语言设置为INVALID'xx'或其他不存在的翻译以使其在django中工作对我来说很奇怪?你能帮我解决一下怎么做?
1 个解决方案
#1
1
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.
路径是在第一次使用后定义的,因此django无法构建默认转换 - 这里修复非常简单。
# 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 :)
LANGUAGE_CODE ='xx'正在创建无效的翻译容器,它将永远不会被使用,并且首次使用其他语言(如pl)的有效设置会产生如此好的副作用:)
#1
1
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.
路径是在第一次使用后定义的,因此django无法构建默认转换 - 这里修复非常简单。
# 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 :)
LANGUAGE_CODE ='xx'正在创建无效的翻译容器,它将永远不会被使用,并且首次使用其他语言(如pl)的有效设置会产生如此好的副作用:)