Skip to content
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

Do not attempt to load en_GB langauge #474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ def test_config_from_language_code(self):
config = widget.get_mce_config(attrs={"id": "id"})
self.assertEqual(config["language"], "en_US")

def test_no_language_for_en_US(self):
def test_no_language_for_en(self):
"""
en_US shouldn't set 'language'
en_US nor en_GB shouldn't set 'language'
(https://github.com/tinymce/tinymce/issues/4228)
"""
widget = TinyMCE()
with override_settings(LANGUAGE_CODE="en-us"):
config = widget.get_mce_config(attrs={"id": "id"})
self.assertNotIn("language", config.keys())
with override_settings(LANGUAGE_CODE="en-gb"):
config = widget.get_mce_config(attrs={"id": "id"})
self.assertNotIn("language", config.keys())
self.assertEqual(config["directionality"], "ltr")

def test_language_override_from_config(self):
Expand Down
2 changes: 1 addition & 1 deletion tinymce/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_mce_config(self, attrs):
mce_config = tinymce.settings.DEFAULT_CONFIG.copy()
if "language" not in mce_config:
mce_config["language"] = get_language_from_django()
if mce_config["language"] == "en_US":
if mce_config["language"] in ["en_GB", "en_US"]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about startswith("en_") to cover all variants?
(unless the language param can only be GB or US, not CA or all the other possibilities)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's the right fix, as someone can provide a custom en_* translation file and this fix would ignore that custom file. I think we should instead fix match_language_with_tinymce and replace if lang.startswith("en") with if lang == 'en_US' at the start of the function, so any en_* variant will go through the standard search for an existing tinyMCE language file.

del mce_config["language"]
else:
mce_config["language"] = match_language_with_tinymce(mce_config["language"])
Expand Down