8000 fix: Added deprecation warning to `get_current_language()` by marksweb · Pull Request #7410 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Added deprecation warning to get_current_language() #7410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Added deprecation warning to `cms.utils.i18n.get_current_languag…
…e()`
  • Loading branch information
marksweb committed Oct 16, 2022
commit c5b3abf160fc4c4daa61595d9bd7becb9b1a7dc0
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ unreleased
* Fix bug where switching color scheme affects other settings
* Unlocalize page and node ids when rendering the page tree in the admin (#7175)
* Fixed permission denied error after page create (#6866)
* Add deprecation warning to ``cms.utils.i18n.get_current_language()`` (#6720)

3.11.0 (2022-08-02)
===================
Expand Down
11 changes: 8 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,10 @@ 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().",
warnings.DeprecationWarning
)
language_code = translation.get_language()
return get_language_code(language_code)

Expand Down
0