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
e34f4e6f
Kaydet (Commit)
e34f4e6f
authored
Ock 26, 2017
tarafından
Claude Paroz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Made ugettext* functions aliases of gettext*
Thanks Tim Graham for the review.
üst
9e9e7373
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
73 deletions
+36
-73
__init__.py
django/utils/translation/__init__.py
+9
-10
trans_null.py
django/utils/translation/trans_null.py
+9
-18
trans_real.py
django/utils/translation/trans_real.py
+6
-18
utils.txt
docs/ref/utils.txt
+6
-9
translation.txt
docs/topics/i18n/translation.txt
+6
-18
No files found.
django/utils/translation/__init__.py
Dosyayı görüntüle @
e34f4e6f
...
...
@@ -78,16 +78,16 @@ def gettext(message):
return
_trans
.
gettext
(
message
)
def
ngettext
(
singular
,
plural
,
number
):
return
_trans
.
ngettext
(
singular
,
plural
,
number
)
# An alias since Django 2.0
ugettext
=
gettext
def
ugettext
(
message
):
return
_trans
.
ugettext
(
message
)
def
ngettext
(
singular
,
plural
,
number
):
return
_trans
.
ngettext
(
singular
,
plural
,
number
)
def
ungettext
(
singular
,
plural
,
number
):
return
_trans
.
ungettext
(
singular
,
plural
,
number
)
# An alias since Django 2.0
ungettext
=
ngettext
def
pgettext
(
context
,
message
):
...
...
@@ -98,8 +98,7 @@ def npgettext(context, singular, plural, number):
return
_trans
.
npgettext
(
context
,
singular
,
plural
,
number
)
gettext_lazy
=
lazy
(
gettext
,
str
)
ugettext_lazy
=
lazy
(
ugettext
,
str
)
gettext_lazy
=
ugettext_lazy
=
lazy
(
gettext
,
str
)
pgettext_lazy
=
lazy
(
pgettext
,
str
)
...
...
@@ -148,8 +147,8 @@ def ngettext_lazy(singular, plural, number=None):
return
lazy_number
(
ngettext
,
str
,
singular
=
singular
,
plural
=
plural
,
number
=
number
)
def
ungettext_lazy
(
singular
,
plural
,
number
=
None
):
return
lazy_number
(
ungettext
,
str
,
singular
=
singular
,
plural
=
plural
,
number
=
number
)
# An alias since Django 2.0
ungettext_lazy
=
ngettext_lazy
def
npgettext_lazy
(
context
,
singular
,
plural
,
number
=
None
):
...
...
django/utils/translation/trans_null.py
Dosyayı görüntüle @
e34f4e6f
...
...
@@ -3,7 +3,13 @@
# settings.USE_I18N = False can use this module rather than trans_real.py.
from
django.conf
import
settings
from
django.utils.encoding
import
force_text
def
gettext
(
message
):
return
message
gettext_noop
=
gettext_lazy
=
_
=
gettext
def
ngettext
(
singular
,
plural
,
number
):
...
...
@@ -15,16 +21,12 @@ def ngettext(singular, plural, number):
ngettext_lazy
=
ngettext
def
ungettext
(
singular
,
plural
,
number
):
return
force_text
(
ngettext
(
singular
,
plural
,
number
))
def
pgettext
(
context
,
message
):
return
u
gettext
(
message
)
return
gettext
(
message
)
def
npgettext
(
context
,
singular
,
plural
,
number
):
return
u
ngettext
(
singular
,
plural
,
number
)
return
ngettext
(
singular
,
plural
,
number
)
def
activate
(
x
):
...
...
@@ -50,17 +52,6 @@ def check_for_language(x):
return
True
def
gettext
(
message
):
return
message
def
ugettext
(
message
):
return
force_text
(
gettext
(
message
))
gettext_noop
=
gettext_lazy
=
_
=
gettext
def
to_locale
(
language
):
p
=
language
.
find
(
'-'
)
if
p
>=
0
:
...
...
django/utils/translation/trans_real.py
Dosyayı görüntüle @
e34f4e6f
...
...
@@ -297,10 +297,9 @@ def catalog():
return
_default
def
do_translate
(
message
,
translation_function
):
def
gettext
(
message
):
"""
Translates 'message' using the given 'translation_function' name -- which
will be either gettext or ugettext. It uses the current thread to find the
Translate the 'message' string. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
"""
...
...
@@ -316,7 +315,7 @@ def do_translate(message, translation_function):
_default
=
_default
or
translation
(
settings
.
LANGUAGE_CODE
)
translation_object
=
getattr
(
_active
,
"value"
,
_default
)
result
=
getattr
(
translation_object
,
translation_function
)
(
eol_message
)
result
=
translation_object
.
gettext
(
eol_message
)
if
isinstance
(
message
,
SafeData
):
return
mark_safe
(
result
)
...
...
@@ -324,17 +323,9 @@ def do_translate(message, translation_function):
return
result
def
gettext
(
message
):
"""Return a string of the translation of the message."""
return
do_translate
(
message
,
'gettext'
)
ugettext
=
gettext
def
pgettext
(
context
,
message
):
msg_with_ctxt
=
"
%
s
%
s
%
s"
%
(
context
,
CONTEXT_SEPARATOR
,
message
)
result
=
u
gettext
(
msg_with_ctxt
)
result
=
gettext
(
msg_with_ctxt
)
if
CONTEXT_SEPARATOR
in
result
:
# Translation not found
# force str, because the lazy version expects str.
...
...
@@ -371,17 +362,14 @@ def ngettext(singular, plural, number):
return
do_ntranslate
(
singular
,
plural
,
number
,
'ngettext'
)
ungettext
=
ngettext
def
npgettext
(
context
,
singular
,
plural
,
number
):
msgs_with_ctxt
=
(
"
%
s
%
s
%
s"
%
(
context
,
CONTEXT_SEPARATOR
,
singular
),
"
%
s
%
s
%
s"
%
(
context
,
CONTEXT_SEPARATOR
,
plural
),
number
)
result
=
u
ngettext
(
*
msgs_with_ctxt
)
result
=
ngettext
(
*
msgs_with_ctxt
)
if
CONTEXT_SEPARATOR
in
result
:
# Translation not found
result
=
u
ngettext
(
singular
,
plural
,
number
)
result
=
ngettext
(
singular
,
plural
,
number
)
return
result
...
...
docs/ref/utils.txt
Dosyayı görüntüle @
e34f4e6f
...
...
@@ -1011,10 +1011,11 @@ appropriate entities.
For a complete discussion on the usage of the following see the
:doc:`translation documentation </topics/i18n/translation>`.
.. function:: gettext(message)
Translates ``message`` and returns it in a UTF-8 bytestring
.
The ``u`` prefix on the functions below comes from a difference in Python 2
between unicode and bytestrings. If your code doesn't support Python 2, use the
functions without the ``u``
.
.. function:: gettext(message)
.. function:: ugettext(message)
Translates ``message`` and returns it as a string.
...
...
@@ -1042,19 +1043,15 @@ For a complete discussion on the usage of the following see the
later.
.. function:: ngettext(singular, plural, number)
Translates ``singular`` and ``plural`` and returns the appropriate string
based on ``number`` in a UTF-8 bytestring.
.. function:: ungettext(singular, plural, number)
Translates ``singular`` and ``plural`` and returns the appropriate string
based on ``number``
as a string
.
based on ``number``.
.. function:: npgettext(context, singular, plural, number)
Translates ``singular`` and ``plural`` and returns the appropriate string
based on ``number`` and the ``context``
as a string
.
based on ``number`` and the ``context``.
.. function:: ngettext_lazy(singular, plural, number)
.. function:: ungettext_lazy(singular, plural, number)
...
...
docs/topics/i18n/translation.txt
Dosyayı görüntüle @
e34f4e6f
...
...
@@ -52,6 +52,12 @@ Specify a translation string by using the function
:func:`~django.utils.translation.ugettext`. It's convention to import this
as a shorter alias, ``_``, to save typing.
.. note::
The ``u`` prefixing of ``gettext`` functions was originally to distinguish
usage between unicode strings and bytestrings on Python 2. For code that
supports only Python 3, they can be used interchangeably. A deprecation for
the prefixed functions may happen in a future Django release.
.. note::
Python's standard library ``gettext`` module installs ``_()`` into the
global namespace, as an alias for ``gettext()``. In Django, we have chosen
...
...
@@ -428,24 +434,6 @@ strings before passing them to non-Django code::
requests.post('https://example.com/send', data={'body': str(body)})
If you try to use a ``ugettext_lazy()`` result where a bytestring (a
:class:`bytes` object) is expected, things won't work as expected since a
``ugettext_lazy()`` object doesn't know how to convert itself to a bytestring.
You can't use a string inside a bytestring, either, so this is consistent with
normal Python behavior. For example, putting a string proxy into a string is
fine::
"Hello %s" % ugettext_lazy("people")
But you can't insert a string into a bytestring and nor can you insert
a string proxy there::
b"Hello %s" % ugettext_lazy("people")
If you ever see output that looks like ``"hello
<django.utils.functional...>"``, you have tried to insert the result of
``ugettext_lazy()`` into a bytestring. That's a bug in your code.
If you don't like the long ``ugettext_lazy`` name, you can just alias it as
``_`` (underscore), like so::
...
...
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