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
002b3d87
Kaydet (Commit)
002b3d87
authored
May 31, 2015
tarafından
Tomáš Ehrlich
Kaydeden (comit)
Tim Graham
Haz 02, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24230 -- Added translated language name for i18n template tag/filter.
üst
9ca0961b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
13 deletions
+59
-13
i18n.py
django/templatetags/i18n.py
+8
-0
__init__.py
django/utils/translation/__init__.py
+8
-3
1.9.txt
docs/releases/1.9.txt
+4
-0
spelling_wordlist
docs/spelling_wordlist
+1
-0
translation.txt
docs/topics/i18n/translation.txt
+11
-0
test_i18n.py
tests/template_tests/syntax_tests/test_i18n.py
+27
-10
No files found.
django/templatetags/i18n.py
Dosyayı görüntüle @
002b3d87
...
...
@@ -215,6 +215,7 @@ def do_get_language_info(parser, token):
{
%
get_language_info for LANGUAGE_CODE as l
%
}
{{ l.code }}
{{ l.name }}
{{ l.name_translated }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
"""
...
...
@@ -238,6 +239,7 @@ def do_get_language_info_list(parser, token):
{
%
for l in langs
%
}
{{ l.code }}
{{ l.name }}
{{ l.name_translated }}
{{ l.name_local }}
{{ l.bidi|yesno:"bi-directional,uni-directional" }}
{
%
endfor
%
}
...
...
@@ -253,6 +255,12 @@ def language_name(lang_code):
return
translation
.
get_language_info
(
lang_code
)[
'name'
]
@register.filter
def
language_name_translated
(
lang_code
):
english_name
=
translation
.
get_language_info
(
lang_code
)[
'name'
]
return
translation
.
ugettext
(
english_name
)
@register.filter
def
language_name_local
(
lang_code
):
return
translation
.
get_language_info
(
lang_code
)[
'name_local'
]
...
...
django/utils/translation/__init__.py
Dosyayı görüntüle @
002b3d87
...
...
@@ -215,17 +215,22 @@ def get_language_info(lang_code):
try
:
lang_info
=
LANG_INFO
[
lang_code
]
if
'fallback'
in
lang_info
and
'name'
not
in
lang_info
:
return
get_language_info
(
lang_info
[
'fallback'
][
0
])
return
lang_info
info
=
get_language_info
(
lang_info
[
'fallback'
][
0
])
else
:
info
=
lang_info
except
KeyError
:
if
'-'
not
in
lang_code
:
raise
KeyError
(
"Unknown language code
%
s."
%
lang_code
)
generic_lang_code
=
lang_code
.
split
(
'-'
)[
0
]
try
:
return
LANG_INFO
[
generic_lang_code
]
info
=
LANG_INFO
[
generic_lang_code
]
except
KeyError
:
raise
KeyError
(
"Unknown language code
%
s and
%
s."
%
(
lang_code
,
generic_lang_code
))
if
info
:
info
[
'name_translated'
]
=
ugettext_lazy
(
info
[
'name'
])
return
info
trim_whitespace_re
=
re
.
compile
(
'
\
s*
\n
\
s*'
)
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
002b3d87
...
...
@@ -187,6 +187,10 @@ Internationalization
for languages which can be written in different scripts, for example Latin
and Cyrillic (e.g. ``be@latin``).
* Added the ``name_translated`` attribute to the object returned by the
:ttag:`get_language_info` template tag. Also added a corresponding template
filter: :tfilter:`language_name_translated`.
Management Commands
^^^^^^^^^^^^^^^^^^^
...
...
docs/spelling_wordlist
Dosyayı görüntüle @
002b3d87
...
...
@@ -515,6 +515,7 @@ naturalday
naturaltime
nd
needsinfo
německy
nestable
neuroscientist
newforms
...
...
docs/topics/i18n/translation.txt
Dosyayı görüntüle @
002b3d87
...
...
@@ -870,6 +870,11 @@ You can then access the information::
Name of language: {{ lang.name_local }}<br />
Name in English: {{ lang.name }}<br />
Bi-directional: {{ lang.bidi }}
Name in the active language: {{ lang.name_translated }}
.. versionadded:: 1.9
The ``name_translated`` attribute was added.
.. templatetag:: get_language_info_list
...
...
@@ -899,6 +904,7 @@ you can iterate over those languages in the template::
.. templatefilter:: language_name
.. templatefilter:: language_name_local
.. templatefilter:: language_bidi
.. templatefilter:: language_name_translated
Template filters
~~~~~~~~~~~~~~~~
...
...
@@ -908,6 +914,11 @@ There are also simple filters available for convenience:
* ``{{ LANGUAGE_CODE|language_name }}`` ("German")
* ``{{ LANGUAGE_CODE|language_name_local }}`` ("Deutsch")
* ``{{ LANGUAGE_CODE|language_bidi }}`` (False)
* ``{{ LANGUAGE_CODE|language_name_translated }}`` ("německy", when active language is Czech)
.. versionadded:: 1.9
The ``language_name_translated`` filter was added.
.. _Django templates: ../templates_python/
...
...
tests/template_tests/syntax_tests/test_i18n.py
Dosyayı görüntüle @
002b3d87
...
...
@@ -342,17 +342,26 @@ class I18nTagTests(SimpleTestCase):
)
@setup
({
'i18n32'
:
'{
%
load i18n
%
}{{ "hu"|language_name }} '
'{{ "hu"|language_name_local }} {{ "hu"|language_bidi }}'
})
'{{ "hu"|language_name_local }} {{ "hu"|language_bidi }} '
'{{ "hu"|language_name_translated }}'
})
def
test_i18n32
(
self
):
output
=
self
.
engine
.
render_to_string
(
'i18n32'
)
self
.
assertEqual
(
output
,
'Hungarian Magyar False'
)
self
.
assertEqual
(
output
,
'Hungarian Magyar False Hungarian'
)
with
translation
.
override
(
'cs'
):
output
=
self
.
engine
.
render_to_string
(
'i18n32'
)
self
.
assertEqual
(
output
,
'Hungarian Magyar False maďarsky'
)
@setup
({
'i18n33'
:
'{
%
load i18n
%
}'
'{{ langcode|language_name }} {{ langcode|language_name_local }} '
'{{ langcode|language_bidi }}'
})
'{{ langcode|language_bidi }}
{{ langcode|language_name_translated }}
'
})
def
test_i18n33
(
self
):
output
=
self
.
engine
.
render_to_string
(
'i18n33'
,
{
'langcode'
:
'nl'
})
self
.
assertEqual
(
output
,
'Dutch Nederlands False'
)
self
.
assertEqual
(
output
,
'Dutch Nederlands False Dutch'
)
with
translation
.
override
(
'cs'
):
output
=
self
.
engine
.
render_to_string
(
'i18n33'
,
{
'langcode'
:
'nl'
})
self
.
assertEqual
(
output
,
'Dutch Nederlands False nizozemsky'
)
# blocktrans handling of variables which are not in the context.
# this should work as if blocktrans was not there (#19915)
...
...
@@ -405,18 +414,26 @@ class I18nTagTests(SimpleTestCase):
# Test whitespace in filter arguments
@setup
({
'i18n38'
:
'{
%
load i18n custom
%
}'
'{
%
get_language_info for "de"|noop:"x y" as l
%
}'
'{{ l.code }}: {{ l.name }}/{{ l.name_local }} bidi={{ l.bidi }}'
})
'{{ l.code }}: {{ l.name }}/{{ l.name_local }}/'
'{{ l.name_translated }} bidi={{ l.bidi }}'
})
def
test_i18n38
(
self
):
output
=
self
.
engine
.
render_to_string
(
'i18n38'
)
self
.
assertEqual
(
output
,
'de: German/Deutsch bidi=False'
)
with
translation
.
override
(
'cs'
):
output
=
self
.
engine
.
render_to_string
(
'i18n38'
)
self
.
assertEqual
(
output
,
'de: German/Deutsch/německy bidi=False'
)
@setup
({
'i18n38_2'
:
'{
%
load i18n custom
%
}'
'{
%
get_language_info_list for langcodes|noop:"x y" as langs
%
}'
'{
%
for l in langs
%
}{{ l.code }}: {{ l.name }}/'
'{{ l.name_local }} bidi={{ l.bidi }}; {
%
endfor
%
}'
})
'{{ l.name_local }}/{{ l.name_translated }} '
'bidi={{ l.bidi }}; {
%
endfor
%
}'
})
def
test_i18n38_2
(
self
):
output
=
self
.
engine
.
render_to_string
(
'i18n38_2'
,
{
'langcodes'
:
[
'it'
,
'no'
]})
self
.
assertEqual
(
output
,
'it: Italian/italiano bidi=False; no: Norwegian/norsk bidi=False; '
)
with
translation
.
override
(
'cs'
):
output
=
self
.
engine
.
render_to_string
(
'i18n38_2'
,
{
'langcodes'
:
[
'it'
,
'fr'
]})
self
.
assertEqual
(
output
,
'it: Italian/italiano/italsky bidi=False; '
'fr: French/français/francouzsky bidi=False; '
)
@setup
({
'template'
:
'{
%
load i18n
%
}{
%
trans
%
}A}'
})
def
test_syntax_error_no_arguments
(
self
):
...
...
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