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
2b20e414
Kaydet (Commit)
2b20e414
authored
Ara 31, 2016
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #19567 -- Removed deprecated javascript_catalog() and json_catalog() views.
üst
933dc627
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
5 additions
and
272 deletions
+5
-272
i18n.py
django/views/i18n.py
+1
-124
1.9.txt
docs/releases/1.9.txt
+2
-2
2.0.txt
docs/releases/2.0.txt
+2
-0
translation.txt
docs/topics/i18n/translation.txt
+0
-133
test_i18n_deprecated.py
tests/view_tests/tests/test_i18n_deprecated.py
+0
-0
urls.py
tests/view_tests/urls.py
+0
-13
No files found.
django/views/i18n.py
Dosyayı görüntüle @
2b20e414
import
importlib
import
itertools
import
itertools
import
json
import
json
import
os
import
os
import
warnings
from
django
import
http
from
django
import
http
from
django.apps
import
apps
from
django.apps
import
apps
...
@@ -10,18 +8,15 @@ from django.conf import settings
...
@@ -10,18 +8,15 @@ from django.conf import settings
from
django.template
import
Context
,
Engine
from
django.template
import
Context
,
Engine
from
django.urls
import
translate_url
from
django.urls
import
translate_url
from
django.utils
import
six
from
django.utils
import
six
from
django.utils._os
import
upath
from
django.utils.deprecation
import
RemovedInDjango20Warning
from
django.utils.encoding
import
force_text
from
django.utils.encoding
import
force_text
from
django.utils.formats
import
get_format
from
django.utils.formats
import
get_format
from
django.utils.http
import
is_safe_url
,
urlunquote
from
django.utils.http
import
is_safe_url
,
urlunquote
from
django.utils.translation
import
(
from
django.utils.translation
import
(
LANGUAGE_SESSION_KEY
,
check_for_language
,
get_language
,
to_locale
,
LANGUAGE_SESSION_KEY
,
check_for_language
,
get_language
,
)
)
from
django.utils.translation.trans_real
import
DjangoTranslation
from
django.utils.translation.trans_real
import
DjangoTranslation
from
django.views.generic
import
View
from
django.views.generic
import
View
DEFAULT_PACKAGES
=
[
'django.conf'
]
LANGUAGE_QUERY_PARAMETER
=
'language'
LANGUAGE_QUERY_PARAMETER
=
'language'
...
@@ -210,69 +205,6 @@ def render_javascript_catalog(catalog=None, plural=None):
...
@@ -210,69 +205,6 @@ def render_javascript_catalog(catalog=None, plural=None):
return
http
.
HttpResponse
(
template
.
render
(
context
),
'text/javascript'
)
return
http
.
HttpResponse
(
template
.
render
(
context
),
'text/javascript'
)
def
get_javascript_catalog
(
locale
,
domain
,
packages
):
app_configs
=
apps
.
get_app_configs
()
allowable_packages
=
set
(
app_config
.
name
for
app_config
in
app_configs
)
allowable_packages
.
update
(
DEFAULT_PACKAGES
)
packages
=
[
p
for
p
in
packages
if
p
in
allowable_packages
]
paths
=
[]
# paths of requested packages
for
package
in
packages
:
p
=
importlib
.
import_module
(
package
)
path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
upath
(
p
.
__file__
)),
'locale'
)
paths
.
append
(
path
)
trans
=
DjangoTranslation
(
locale
,
domain
=
domain
,
localedirs
=
paths
)
trans_cat
=
trans
.
_catalog
plural
=
None
if
''
in
trans_cat
:
for
line
in
trans_cat
[
''
]
.
split
(
'
\n
'
):
if
line
.
startswith
(
'Plural-Forms:'
):
plural
=
line
.
split
(
':'
,
1
)[
1
]
.
strip
()
if
plural
is
not
None
:
# this should actually be a compiled function of a typical plural-form:
# Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 :
# n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
plural
=
[
el
.
strip
()
for
el
in
plural
.
split
(
';'
)
if
el
.
strip
()
.
startswith
(
'plural='
)][
0
]
.
split
(
'='
,
1
)[
1
]
pdict
=
{}
maxcnts
=
{}
catalog
=
{}
trans_fallback_cat
=
trans
.
_fallback
.
_catalog
if
trans
.
_fallback
else
{}
for
key
,
value
in
itertools
.
chain
(
six
.
iteritems
(
trans_cat
),
six
.
iteritems
(
trans_fallback_cat
)):
if
key
==
''
or
key
in
catalog
:
continue
if
isinstance
(
key
,
six
.
string_types
):
catalog
[
key
]
=
value
elif
isinstance
(
key
,
tuple
):
msgid
=
key
[
0
]
cnt
=
key
[
1
]
maxcnts
[
msgid
]
=
max
(
cnt
,
maxcnts
.
get
(
msgid
,
0
))
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
)]
return
catalog
,
plural
def
_get_locale
(
request
):
language
=
request
.
GET
.
get
(
LANGUAGE_QUERY_PARAMETER
)
if
not
(
language
and
check_for_language
(
language
)):
language
=
get_language
()
return
to_locale
(
language
)
def
_parse_packages
(
packages
):
if
packages
is
None
:
packages
=
list
(
DEFAULT_PACKAGES
)
elif
isinstance
(
packages
,
six
.
string_types
):
packages
=
packages
.
split
(
'+'
)
return
packages
def
null_javascript_catalog
(
request
,
domain
=
None
,
packages
=
None
):
def
null_javascript_catalog
(
request
,
domain
=
None
,
packages
=
None
):
"""
"""
Returns "identity" versions of the JavaScript i18n functions -- i.e.,
Returns "identity" versions of the JavaScript i18n functions -- i.e.,
...
@@ -281,61 +213,6 @@ def null_javascript_catalog(request, domain=None, packages=None):
...
@@ -281,61 +213,6 @@ def null_javascript_catalog(request, domain=None, packages=None):
return
render_javascript_catalog
()
return
render_javascript_catalog
()
def
javascript_catalog
(
request
,
domain
=
'djangojs'
,
packages
=
None
):
"""
Returns the selected language catalog as a javascript library.
Receives the list of packages to check for translations in the
packages parameter either from an infodict or as a +-delimited
string from the request. Default is 'django.conf'.
Additionally you can override the gettext domain for this view,
but usually you don't want to do that, as JavaScript messages
go to the djangojs domain. But this might be needed if you
deliver your JavaScript source from Django templates.
"""
warnings
.
warn
(
"The javascript_catalog() view is deprecated in favor of the "
"JavaScriptCatalog view."
,
RemovedInDjango20Warning
,
stacklevel
=
2
)
locale
=
_get_locale
(
request
)
packages
=
_parse_packages
(
packages
)
catalog
,
plural
=
get_javascript_catalog
(
locale
,
domain
,
packages
)
return
render_javascript_catalog
(
catalog
,
plural
)
def
json_catalog
(
request
,
domain
=
'djangojs'
,
packages
=
None
):
"""
Return the selected language catalog as a JSON object.
Receives the same parameters as javascript_catalog(), but returns
a response with a JSON object of the following format:
{
"catalog": {
# Translations catalog
},
"formats": {
# Language formats for date, time, etc.
},
"plural": '...' # Expression for plural forms, or null.
}
"""
warnings
.
warn
(
"The json_catalog() view is deprecated in favor of the "
"JSONCatalog view."
,
RemovedInDjango20Warning
,
stacklevel
=
2
)
locale
=
_get_locale
(
request
)
packages
=
_parse_packages
(
packages
)
catalog
,
plural
=
get_javascript_catalog
(
locale
,
domain
,
packages
)
data
=
{
'catalog'
:
catalog
,
'formats'
:
get_formats
(),
'plural'
:
plural
,
}
return
http
.
JsonResponse
(
data
)
class
JavaScriptCatalog
(
View
):
class
JavaScriptCatalog
(
View
):
"""
"""
Return the selected language catalog as a JavaScript library.
Return the selected language catalog as a JavaScript library.
...
...
docs/releases/1.9.txt
Dosyayı görüntüle @
2b20e414
...
@@ -384,7 +384,7 @@ Internationalization
...
@@ -384,7 +384,7 @@ Internationalization
* The :func:`django.views.i18n.set_language` view now properly redirects to
* The :func:`django.views.i18n.set_language` view now properly redirects to
:ref:`translated URLs <url-internationalization>`, when available.
:ref:`translated URLs <url-internationalization>`, when available.
* The
:func:`django.views.i18n.javascript_catalog
` view now works correctly
* The
``django.views.i18n.javascript_catalog()`
` view now works correctly
if used multiple times with different configurations on the same page.
if used multiple times with different configurations on the same page.
* The :func:`django.utils.timezone.make_aware` function gained an ``is_dst``
* The :func:`django.utils.timezone.make_aware` function gained an ``is_dst``
...
@@ -394,7 +394,7 @@ Internationalization
...
@@ -394,7 +394,7 @@ Internationalization
for languages which can be written in different scripts, for example Latin
for languages which can be written in different scripts, for example Latin
and Cyrillic (e.g. ``be@latin``).
and Cyrillic (e.g. ``be@latin``).
* Added the
:func:`django.views.i18n.json_catalog
` view to help build a custom
* Added the
``django.views.i18n.json_catalog()`
` view to help build a custom
client-side i18n library upon Django translations. It returns a JSON object
client-side i18n library upon Django translations. It returns a JSON object
containing a translations catalog, formatting settings, and a plural rule.
containing a translations catalog, formatting settings, and a plural rule.
...
...
docs/releases/2.0.txt
Dosyayı görüntüle @
2b20e414
...
@@ -366,3 +366,5 @@ these features.
...
@@ -366,3 +366,5 @@ these features.
* The keyword arguments ``virtual_only`` in ``Field.contribute_to_class()`` and
* The keyword arguments ``virtual_only`` in ``Field.contribute_to_class()`` and
``virtual`` in ``Model._meta.add_field()`` are removed.
``virtual`` in ``Model._meta.add_field()`` are removed.
* The ``javascript_catalog()`` and ``json_catalog()`` views are removed.
docs/topics/i18n/translation.txt
Dosyayı görüntüle @
2b20e414
...
@@ -1049,88 +1049,6 @@ If you use more than one ``JavaScriptCatalog`` view on a site and some of them
...
@@ -1049,88 +1049,6 @@ If you use more than one ``JavaScriptCatalog`` view on a site and some of them
define the same strings, the strings in the catalog that was loaded last take
define the same strings, the strings in the catalog that was loaded last take
precedence.
precedence.
The ``javascript_catalog`` view
-------------------------------
.. function:: javascript_catalog(request, domain='djangojs', packages=None)
.. deprecated:: 1.10
``javascript_catalog()`` is deprecated in favor of
:class:`JavaScriptCatalog` and will be removed in Django 2.0.
The main solution to these problems is the
:meth:`django.views.i18n.javascript_catalog` view, which sends out a JavaScript
code library with functions that mimic the ``gettext`` interface, plus an array
of translation strings. Those translation strings are taken from applications or
Django core, according to what you specify in either the ``info_dict`` or the
URL. Paths listed in :setting:`LOCALE_PATHS` are also included.
You hook it up like this::
from django.views.i18n import javascript_catalog
js_info_dict = {
'packages': ('your.app.package',),
}
urlpatterns = [
url(r'^jsi18n/$', javascript_catalog, js_info_dict, name='javascript-catalog'),
]
Each string in ``packages`` should be in Python dotted-package syntax (the
same format as the strings in :setting:`INSTALLED_APPS`) and should refer to a
package that contains a ``locale`` directory. If you specify multiple packages,
all those catalogs are merged into one catalog. This is useful if you have
JavaScript that uses strings from different applications.
The precedence of translations is such that the packages appearing later in the
``packages`` argument have higher precedence than the ones appearing at the
beginning, this is important in the case of clashing translations for the same
literal.
By default, the view uses the ``djangojs`` gettext domain. This can be
changed by altering the ``domain`` argument.
You can make the view dynamic by putting the packages into the URL pattern::
urlpatterns = [
url(r'^jsi18n/(?P<packages>\S+?)/$', javascript_catalog, name='javascript-catalog'),
]
With this, you specify the packages as a list of package names delimited by '+'
signs in the URL. This is especially useful if your pages use code from
different apps and this changes often and you don't want to pull in one big
catalog file. As a security measure, these values can only be either
``django.conf`` or any package from the :setting:`INSTALLED_APPS` setting.
You can also split the catalogs in multiple URLs and load them as you need in
your sites::
js_info_dict_app = {
'packages': ('your.app.package',),
}
js_info_dict_other_app = {
'packages': ('your.other.app.package',),
}
urlpatterns = [
url(r'^jsi18n/app/$', javascript_catalog, js_info_dict_app),
url(r'^jsi18n/other_app/$', javascript_catalog, js_info_dict_other_app),
]
If you use more than one ``javascript_catalog`` on a site and some of them
define the same strings, the strings in the catalog that was loaded last take
precedence.
The JavaScript translations found in the paths listed in the
:setting:`LOCALE_PATHS` setting are also always included. To keep consistency
with the translations lookup order algorithm used for Python and templates, the
directories listed in :setting:`LOCALE_PATHS` have the highest precedence with
the ones appearing first having higher precedence than the ones appearing
later.
Using the JavaScript translation catalog
Using the JavaScript translation catalog
----------------------------------------
----------------------------------------
...
@@ -1326,57 +1244,6 @@ The ``JSONCatalog`` view
...
@@ -1326,57 +1244,6 @@ The ``JSONCatalog`` view
.. JSON doesn't allow comments so highlighting as JSON won't work here.
.. JSON doesn't allow comments so highlighting as JSON won't work here.
The ``json_catalog`` view
-------------------------
.. function:: json_catalog(request, domain='djangojs', packages=None)
.. deprecated:: 1.10
``json_catalog()`` is deprecated in favor of :class:`JSONCatalog` and will
be removed in Django 2.0.
In order to use another client-side library to handle translations, you may
want to take advantage of the ``json_catalog()`` view. It's similar to
:meth:`~django.views.i18n.javascript_catalog` but returns a JSON response.
The JSON object contains i18n formatting settings (those available for
`get_format`_), a plural rule (as a ``plural`` part of a GNU gettext
``Plural-Forms`` expression), and translation strings. The translation strings
are taken from applications or Django's own translations, according to what is
specified either via ``urlpatterns`` arguments or as request parameters. Paths
listed in :setting:`LOCALE_PATHS` are also included.
The view is hooked up to your application and configured in the same fashion as
:meth:`~django.views.i18n.javascript_catalog` (namely, the ``domain`` and
``packages`` arguments behave identically)::
from django.views.i18n import json_catalog
js_info_dict = {
'packages': ('your.app.package',),
}
urlpatterns = [
url(r'^jsoni18n/$', json_catalog, js_info_dict),
]
The response format is as follows:
.. code-block:: text
{
"catalog": {
# Translations catalog
},
"formats": {
# Language formats for date, time, etc.
},
"plural": "..." # Expression for plural forms, or null.
}
.. JSON doesn't allow comments so highlighting as JSON won't work here.
Note on performance
Note on performance
-------------------
-------------------
...
...
tests/view_tests/tests/test_i18n_deprecated.py
deleted
100644 → 0
Dosyayı görüntüle @
933dc627
This diff is collapsed.
Click to expand it.
tests/view_tests/urls.py
Dosyayı görüntüle @
2b20e414
...
@@ -72,19 +72,6 @@ urlpatterns = [
...
@@ -72,19 +72,6 @@ urlpatterns = [
url
(
r'technical404/$'
,
views
.
technical404
,
name
=
"my404"
),
url
(
r'technical404/$'
,
views
.
technical404
,
name
=
"my404"
),
url
(
r'classbased404/$'
,
views
.
Http404View
.
as_view
()),
url
(
r'classbased404/$'
,
views
.
Http404View
.
as_view
()),
# deprecated i18n views
url
(
r'^old_jsi18n/$'
,
i18n
.
javascript_catalog
,
js_info_dict
),
url
(
r'^old_jsi18n/app1/$'
,
i18n
.
javascript_catalog
,
js_info_dict_app1
),
url
(
r'^old_jsi18n/app2/$'
,
i18n
.
javascript_catalog
,
js_info_dict_app2
),
url
(
r'^old_jsi18n/app5/$'
,
i18n
.
javascript_catalog
,
js_info_dict_app5
),
url
(
r'^old_jsi18n_english_translation/$'
,
i18n
.
javascript_catalog
,
js_info_dict_english_translation
),
url
(
r'^old_jsi18n_multi_packages1/$'
,
i18n
.
javascript_catalog
,
js_info_dict_multi_packages1
),
url
(
r'^old_jsi18n_multi_packages2/$'
,
i18n
.
javascript_catalog
,
js_info_dict_multi_packages2
),
url
(
r'^old_jsi18n_admin/$'
,
i18n
.
javascript_catalog
,
js_info_dict_admin
),
url
(
r'^old_jsi18n_template/$'
,
views
.
old_jsi18n
),
url
(
r'^old_jsi18n_multi_catalogs/$'
,
views
.
old_jsi18n_multi_catalogs
),
url
(
r'^old_jsoni18n/$'
,
i18n
.
json_catalog
,
js_info_dict
),
# i18n views
# i18n views
url
(
r'^i18n/'
,
include
(
'django.conf.urls.i18n'
)),
url
(
r'^i18n/'
,
include
(
'django.conf.urls.i18n'
)),
url
(
r'^jsi18n/$'
,
i18n
.
JavaScriptCatalog
.
as_view
(
packages
=
[
'view_tests'
])),
url
(
r'^jsi18n/$'
,
i18n
.
JavaScriptCatalog
.
as_view
(
packages
=
[
'view_tests'
])),
...
...
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