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
79058155
Kaydet (Commit)
79058155
authored
Haz 27, 2017
tarafından
Sebastian Sangervasi
Kaydeden (comit)
Tim Graham
Şub 23, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #27449 -- Added django.utils.translation.get_supported_language_variant().
üst
50339991
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
1 deletion
+74
-1
__init__.py
django/utils/translation/__init__.py
+4
-0
trans_null.py
django/utils/translation/trans_null.py
+7
-0
utils.txt
docs/ref/utils.txt
+17
-0
2.1.txt
docs/releases/2.1.txt
+2
-1
tests.py
tests/i18n/tests.py
+44
-0
No files found.
django/utils/translation/__init__.py
Dosyayı görüntüle @
79058155
...
@@ -205,6 +205,10 @@ def get_language_from_path(path):
...
@@ -205,6 +205,10 @@ def get_language_from_path(path):
return
_trans
.
get_language_from_path
(
path
)
return
_trans
.
get_language_from_path
(
path
)
def
get_supported_language_variant
(
lang_code
,
*
,
strict
=
False
):
return
_trans
.
get_supported_language_variant
(
lang_code
,
strict
)
def
templatize
(
src
,
**
kwargs
):
def
templatize
(
src
,
**
kwargs
):
from
.template
import
templatize
from
.template
import
templatize
return
templatize
(
src
,
**
kwargs
)
return
templatize
(
src
,
**
kwargs
)
...
...
django/utils/translation/trans_null.py
Dosyayı görüntüle @
79058155
...
@@ -66,3 +66,10 @@ def get_language_from_request(request, check_path=False):
...
@@ -66,3 +66,10 @@ def get_language_from_request(request, check_path=False):
def
get_language_from_path
(
request
):
def
get_language_from_path
(
request
):
return
None
return
None
def
get_supported_language_variant
(
lang_code
,
strict
=
False
):
if
lang_code
==
settings
.
LANGUAGE_CODE
:
return
lang_code
else
:
raise
LookupError
(
lang_code
)
docs/ref/utils.txt
Dosyayı görüntüle @
79058155
...
@@ -1092,6 +1092,23 @@ functions without the ``u``.
...
@@ -1092,6 +1092,23 @@ functions without the ``u``.
for whether its path begins with a language code listed in the
for whether its path begins with a language code listed in the
:setting:`LANGUAGES` setting.
:setting:`LANGUAGES` setting.
.. function:: get_supported_language_variant(lang_code, strict=False)
.. versionadded:: 2.1
Returns ``lang_code`` if it's in the :setting:`LANGUAGES` setting, possibly
selecting a more generic variant. For example, ``'es'`` is returned if
``lang_code`` is ``'es-ar'`` and ``'es'`` is in :setting:`LANGUAGES` but
``'es-ar'`` isn't.
If ``strict`` is ``False`` (the default), a country-specific variant may
be returned when neither the language code nor its generic variant is found.
For example, if only ``'es-co'`` is in :setting:`LANGUAGES`, that's
returned for ``lang_code``\s like ``'es'`` and ``'es-ar'``. Those matches
aren't returned if ``strict=True``.
Raises :exc:`LookupError` if nothing is found.
.. function:: to_locale(language)
.. function:: to_locale(language)
Turns a language name (en-us) into a locale name (en_US).
Turns a language name (en-us) into a locale name (en_US).
...
...
docs/releases/2.1.txt
Dosyayı görüntüle @
79058155
...
@@ -162,7 +162,8 @@ Generic Views
...
@@ -162,7 +162,8 @@ Generic Views
Internationalization
Internationalization
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~
* ...
* Added the :meth:`~django.utils.translation.get_supported_language_variant`
function.
Management Commands
Management Commands
~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~
...
...
tests/i18n/tests.py
Dosyayı görüntüle @
79058155
...
@@ -1306,6 +1306,50 @@ class MiscTests(SimpleTestCase):
...
@@ -1306,6 +1306,50 @@ class MiscTests(SimpleTestCase):
r
.
META
=
{
'HTTP_ACCEPT_LANGUAGE'
:
'de'
}
r
.
META
=
{
'HTTP_ACCEPT_LANGUAGE'
:
'de'
}
self
.
assertEqual
(
g
(
r
),
'zh-hans'
)
self
.
assertEqual
(
g
(
r
),
'zh-hans'
)
@override_settings
(
USE_I18N
=
True
,
LANGUAGES
=
[
(
'en'
,
'English'
),
(
'de'
,
'German'
),
(
'de-at'
,
'Austrian German'
),
(
'pt-br'
,
'Portuguese (Brazil)'
),
],
)
def
test_get_supported_language_variant_real
(
self
):
g
=
trans_real
.
get_supported_language_variant
self
.
assertEqual
(
g
(
'en'
),
'en'
)
self
.
assertEqual
(
g
(
'en-gb'
),
'en'
)
self
.
assertEqual
(
g
(
'de'
),
'de'
)
self
.
assertEqual
(
g
(
'de-at'
),
'de-at'
)
self
.
assertEqual
(
g
(
'de-ch'
),
'de'
)
self
.
assertEqual
(
g
(
'pt-br'
),
'pt-br'
)
self
.
assertEqual
(
g
(
'pt'
),
'pt-br'
)
self
.
assertEqual
(
g
(
'pt-pt'
),
'pt-br'
)
with
self
.
assertRaises
(
LookupError
):
g
(
'pt'
,
strict
=
True
)
with
self
.
assertRaises
(
LookupError
):
g
(
'pt-pt'
,
strict
=
True
)
with
self
.
assertRaises
(
LookupError
):
g
(
'xyz'
)
with
self
.
assertRaises
(
LookupError
):
g
(
'xy-zz'
)
def
test_get_supported_language_variant_null
(
self
):
g
=
trans_null
.
get_supported_language_variant
self
.
assertEqual
(
g
(
settings
.
LANGUAGE_CODE
),
settings
.
LANGUAGE_CODE
)
with
self
.
assertRaises
(
LookupError
):
g
(
'pt'
)
with
self
.
assertRaises
(
LookupError
):
g
(
'de'
)
with
self
.
assertRaises
(
LookupError
):
g
(
'de-at'
)
with
self
.
assertRaises
(
LookupError
):
g
(
'de'
,
strict
=
True
)
with
self
.
assertRaises
(
LookupError
):
g
(
'de-at'
,
strict
=
True
)
with
self
.
assertRaises
(
LookupError
):
g
(
'xyz'
)
@override_settings
(
@override_settings
(
LANGUAGES
=
[
LANGUAGES
=
[
(
'en'
,
'English'
),
(
'en'
,
'English'
),
...
...
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