2014-09-18 2 views
1

러시아어로 django.po에서 사용자 지정 Plural-Schemes를 사용하고 싶지만 변경하면 ungettext 결과에 영향을 미치지 않습니다.django.po에서 사용자 정의 Plural-Forms을 어떻게 사용합니까?

장고가없는 동일한 번역 파일을 사용하면 Plural-Forms이 올바르게 작동한다는 것을 알게되었습니다.

다음은 django.po 파일입니다.

msgid "" 
msgstr "" 
"Report-Msgid-Bugs-To: \n" 
"POT-Creation-Date: 2014-09-18 01:26+0000\n" 
"Language: ru\n" 
"MIME-Version: 1.0\n" 
"Content-Type: text/plain; charset=UTF-8\n" 
"Content-Transfer-Encoding: 8bit\n" 
"Plural-Forms: nplurals=4; plural=(n==1 ? 0 : n%10==1 && n%100!=11 ? 1 : n" 
"%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 2 : 3)\n" 

#: testapp/test.py:5 
#, python-format 
msgid "One new notification." 
msgid_plural "%(count)s new notifications." 
msgstr[0] "Одно новое оповещение." 
msgstr[1] "%(count)s новое оповещение." 
msgstr[2] "%(count)s новых оповещения." 
msgstr[3] "%(count)s новых оповещений." 

나는이 인쇄되어 다음

import gettext 

filename = "testp/conf/locale/ru/LC_MESSAGES/django.mo" 
trans = gettext.GNUTranslations(open(filename, "rb")) 
trans.install() 

def translated_message(notifications_count): 
    return trans.ungettext(
     "One new notification.", 
     "%(count)s new notifications.", 
     notifications_count 
    ) % {"count": notifications_count} 

print translated_message(1) 
print translated_message(2) 
print translated_message(5) 
print translated_message(51) 

실행하는 경우 :

Одно новое оповещение. 
2 новых оповещения. 
5 новых оповещений. 
51 новое оповещение. 

을 그리고 이것은 정확히 내가 ungettext의 결과로 기대하는 것입니다.

그러나 동일한 컴파일 된 변환 파일 (django.mo)이 장고 프로젝트에서 사용될 때 출력이 다릅니다. 그것은이로 변경 django.utils.translation.ungettext와

는 :

Одно новое оповещение. 
2 новое оповещение. 
5 новых оповещения. 
Одно новое оповещение. 

그것은 분명이 경우 양식 (msgstr가) 제대로 읽을 것을 의미하지만, 복수-양식 (무시 즉, 일반을 러시아 언어에 대한 체계가 내가 정의한 것 대신에 사용된다).

답변

1

모든 카탈로그는 장고에서 병합되므로 질문에 설명 된 작업을 지금 수행 할 수 없습니다.

아마도 가장 깨끗한 해결책은 gettext를 직접 사용하는 것일 수 있습니다.

this ticket도 참조하십시오.

관련 문제