Skip to content

Commit

Permalink
fix: Added deprecation warning to get_current_language() (#7410)
Browse files Browse the repository at this point in the history
* fix: Added deprecation warning to `cms.utils.i18n.get_current_language()`

* fix: Added deprecation warning to `cms.utils.i18n.get_current_language()`

* Added stack level to deprecation warning

Co-authored-by: Fabian Braun <fsbraun@gmx.de>
  • Loading branch information
marksweb and fsbraun committed Oct 29, 2022
1 parent 068e115 commit 2788f75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ unreleased
* Unlocalize page and node ids when rendering the page tree in the admin (#7175)
* Fixed permission denied error after page create (#6866)
* Improved performance when using CMS_RAW_ID_USERS=True on a Postgres DB with many users
* Add deprecation warning to ``cms.utils.i18n.get_current_language()`` (#6720)

3.11.0 (2022-08-02)
===================
Expand Down
12 changes: 9 additions & 3 deletions cms/utils/i18n.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from contextlib import contextmanager

from django.conf import settings
Expand Down Expand Up @@ -59,13 +60,13 @@ def get_language_code(language_code, site_id=None):

languages = get_language_list(site_id)

if language_code in languages: # direct hit
if language_code in languages: # direct hit
return language_code

for lang in languages:
if language_code.split('-')[0] == lang: # base language hit
if language_code.split('-')[0] == lang: # base language hit
return lang
if lang.split('-')[0] == language_code: # base language hit
if lang.split('-')[0] == language_code: # base language hit
return lang
return language_code

Expand All @@ -77,6 +78,11 @@ def get_current_language():
It's a replacement for Django's translation.get_language() to make sure the LANGUAGE_CODE will be found in LANGUAGES.
Overcomes this issue: https://code.djangoproject.com/ticket/9340
"""
warnings.warn(
"get_current_language() is deprecated; use django.utils.translation.get_language().",
DeprecationWarning,
stacklevel=2
)
language_code = translation.get_language()
return get_language_code(language_code)

Expand Down

0 comments on commit 2788f75

Please sign in to comment.