Skip to content

Fix reflang regex pattern to include language code with more than 2 characters #306

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

Open
wants to merge 2 commits into
base: develop
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
Binary file added rosetta/locale/xx_XX/LC_MESSAGES/django.mo
Binary file not shown.
33 changes: 33 additions & 0 deletions rosetta/locale/xx_XX/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: Rosetta\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-02-28 13:36+0100\n"
"PO-Revision-Date: 2008-09-22 11:02\n"
"Last-Translator: Admin Admin <admin@admin.com>\n"
"Language-Team: xx_XX <LL@li.org>\n"
"Language: xx_XX\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Translated-Using: django-rosetta 0.4.RC2\n"

msgid "String 1"
msgstr ""

msgid "String 2"
msgstr ""

#. Translators: This is a text of the base template
#: templates/base.html:43
msgid "String 3 with comment"
msgstr ""

msgctxt "Context hint"
msgid "String 4"
msgstr ""
23 changes: 23 additions & 0 deletions rosetta/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def xx_form_url(self):
kwargs = {"po_filter": "third-party", "lang_id": "xx", "idx": 0}
return reverse("rosetta-form", kwargs=kwargs)

@property
def xx_XX_form_url(self):
kwargs = {"po_filter": "third-party", "lang_id": "xx-XX", "idx": 0}
return reverse("rosetta-form", kwargs=kwargs)

@property
def all_file_list_url(self):
return reverse("rosetta-file-list", kwargs={"po_filter": "all"})
Expand Down Expand Up @@ -670,6 +675,24 @@ def test_33_reflang(self):
'<span class="message">translated-string1</span>' in r.content.decode()
)

@override_settings(
ROSETTA_ENABLE_REFLANG=True, ROSETTA_LANGUAGES=(("xx", "xx dummy language"), ("xx-XX", "xx_XX dummy language"), )
)
def test_34_reflang_longer_2_characters(self):
self.copy_po_file_from_template("./django.po.issue60.template")
r = self.client.get(self.xx_XX_form_url)

# Verify that there's an option to select a reflang
self.assertTrue(
'<option value="?ref_lang=xx-XX">xx_XX dummy language</option>' in r.content.decode()
)

r = self.client.get(self.xx_XX_form_url + "?ref_lang=xx")
# The translated string in the test PO file ends up in the "Reference" column
self.assertTrue(
'<span class="message">translated-string1</span>' in r.content.decode()
)

def test_show_occurrences(self):
r = self.client.get(self.xx_form_url)
# Verify that occurrences in view
Expand Down
6 changes: 3 additions & 3 deletions rosetta/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.utils.decorators import method_decorator
from django.utils.encoding import force_bytes
from django.utils.functional import Promise, cached_property
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_lazy as _, to_locale
from django.views.decorators.cache import never_cache
from django.views.generic import TemplateView, View

Expand Down Expand Up @@ -586,9 +586,9 @@ def ref_lang_po_file(self):
ref_pofile = None
if rosetta_settings.ENABLE_REFLANG and self.ref_lang != "msgid":
replacement = "{separator}locale{separator}{ref_lang}".format(
separator=os.sep, ref_lang=self.ref_lang
separator=os.sep, ref_lang=to_locale(self.ref_lang)
)
pattern = r"\{separator}locale\{separator}[a-z]{{2}}".format(
pattern = r"\{separator}locale\{separator}[a-z]{{2}}(?:_[A-Z]{{2}})?".format(
separator=os.sep
)
ref_fn = re.sub(pattern, replacement, self.po_file_path)
Expand Down