Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
eb66057c
Kaydet (Commit)
eb66057c
authored
May 18, 2017
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #28221 -- Honor plural number in JavaScriptCatalog
üst
59ab1b26
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
8 deletions
+26
-8
i18n.py
django/views/i18n.py
+26
-8
No files found.
django/views/i18n.py
Dosyayı görüntüle @
eb66057c
import
itertools
import
json
import
os
import
re
from
urllib.parse
import
unquote
from
django.apps
import
apps
...
...
@@ -234,12 +235,31 @@ class JavaScriptCatalog(View):
# paths of requested packages
return
[
os
.
path
.
join
(
app
.
path
,
'locale'
)
for
app
in
app_configs
]
def
get_plural
(
self
):
plural
=
None
@property
def
_num_plurals
(
self
):
"""
Return the number of plurals for this catalog language, or 2 if no
plural string is available.
"""
match
=
re
.
search
(
r'nplurals=\s*(\d+)'
,
self
.
_plural_string
or
''
)
if
match
:
return
int
(
match
.
groups
()[
0
])
return
2
@property
def
_plural_string
(
self
):
"""
Return the plural string (including nplurals) for this catalog language,
or None if no plural string is available.
"""
if
''
in
self
.
translation
.
_catalog
:
for
line
in
self
.
translation
.
_catalog
[
''
]
.
split
(
'
\n
'
):
if
line
.
startswith
(
'Plural-Forms:'
):
plural
=
line
.
split
(
':'
,
1
)[
1
]
.
strip
()
return
line
.
split
(
':'
,
1
)[
1
]
.
strip
()
return
None
def
get_plural
(
self
):
plural
=
self
.
_plural_string
if
plural
is
not
None
:
# This should be a compiled function of a typical plural-form:
# Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 :
...
...
@@ -249,7 +269,7 @@ class JavaScriptCatalog(View):
def
get_catalog
(
self
):
pdict
=
{}
maxcnts
=
{}
num_plurals
=
self
.
_num_plurals
catalog
=
{}
trans_cat
=
self
.
translation
.
_catalog
trans_fallback_cat
=
self
.
translation
.
_fallback
.
_catalog
if
self
.
translation
.
_fallback
else
{}
...
...
@@ -259,14 +279,12 @@ class JavaScriptCatalog(View):
if
isinstance
(
key
,
str
):
catalog
[
key
]
=
value
elif
isinstance
(
key
,
tuple
):
msgid
=
key
[
0
]
cnt
=
key
[
1
]
maxcnts
[
msgid
]
=
max
(
cnt
,
maxcnts
.
get
(
msgid
,
0
))
msgid
,
cnt
=
key
pdict
.
setdefault
(
msgid
,
{})[
cnt
]
=
value
else
:
raise
TypeError
(
key
)
for
k
,
v
in
pdict
.
items
():
catalog
[
k
]
=
[
v
.
get
(
i
,
''
)
for
i
in
range
(
maxcnts
[
k
]
+
1
)]
catalog
[
k
]
=
[
v
.
get
(
i
,
''
)
for
i
in
range
(
num_plurals
)]
return
catalog
def
get_context_data
(
self
,
**
kwargs
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment