From 83b65717f23bd2d36903d9c825010899a5493f61 Mon Sep 17 00:00:00 2001 From: Marco Bonetti Date: Mon, 14 Sep 2015 10:19:45 +0200 Subject: [PATCH] Added support for composite locales --- CHANGES | 1 + rosetta/poutil.py | 4 +-- rosetta/tests/tests.py | 24 ++++++------- rosetta/tests/urls.py | 7 ++-- rosetta/tests/views.py | 1 - .../locale/bs-Cyrl-BA/LC_MESSAGES/django.po | 34 ++++++++++++++++++ testproject/locale/fr/LC_MESSAGES/django.po | 2 +- .../locale/fr_FR.utf8/LC_MESSAGES/django.po | 2 +- testproject/locale/xx/LC_MESSAGES/django.mo | Bin 1498 -> 0 bytes testproject/locale/xx/LC_MESSAGES/django.po | 8 +---- testproject/settings.py | 2 ++ 11 files changed, 57 insertions(+), 28 deletions(-) create mode 100644 testproject/locale/bs-Cyrl-BA/LC_MESSAGES/django.po delete mode 100644 testproject/locale/xx/LC_MESSAGES/django.mo diff --git a/CHANGES b/CHANGES index 3a453b3..54d1da3 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,7 @@ Version 0.7.7 (unreleased) * Include the testproject in the sdist tarball to allow Debian to run tests during installation (Issue #137, thanks @fladi) * Display an explicit error message to the enduser when saving the POfile fails for some reason (Issue #135, thanks @pgcd) * Added support for PEP 3101 string formatting (PR #140, thanks @adamjforster) +* Added support for composite locales, e.g. 'bs-Cyrl-BA' (Issue #142, thanks @felarov) Version 0.7.6 diff --git a/rosetta/poutil.py b/rosetta/poutil.py index f2150c6..64553f5 100644 --- a/rosetta/poutil.py +++ b/rosetta/poutil.py @@ -143,10 +143,10 @@ def find_pos(lang, project_apps=True, django_apps=False, third_party_apps=False) ret = set() langs = [lang, ] if u'-' in lang: - _l, _c = map(lambda x: x.lower(), lang.split(u'-')) + _l, _c = map(lambda x: x.lower(), lang.split(u'-', 1)) langs += [u'%s_%s' % (_l, _c), u'%s_%s' % (_l, _c.upper()), ] elif u'_' in lang: - _l, _c = map(lambda x: x.lower(), lang.split(u'_')) + _l, _c = map(lambda x: x.lower(), lang.split(u'_', 1)) langs += [u'%s-%s' % (_l, _c), u'%s-%s' % (_l, _c.upper()), ] paths = map(os.path.normpath, paths) diff --git a/rosetta/tests/tests.py b/rosetta/tests/tests.py index ac7535b..ef03055 100644 --- a/rosetta/tests/tests.py +++ b/rosetta/tests/tests.py @@ -7,24 +7,13 @@ from django.core.cache import cache from django.template.defaultfilters import floatformat from django.test import TestCase from django.test.client import Client +from django.dispatch import receiver from rosetta.conf import settings as rosetta_settings from rosetta.signals import entry_changed, post_save import os import shutil import six import django -import json - - -try: - from django.dispatch import receiver -except ImportError: - # We might be in django < 1.3, so backport this function - def receiver(signal, **kwargs): - def _decorator(func): - signal.connect(func, **kwargs) - return func - return _decorator class RosettaTestCase(TestCase): @@ -54,7 +43,11 @@ class RosettaTestCase(TestCase): self.client2.login(username='test_admin2', password='test_password') self.__old_settings_languages = settings.LANGUAGES - settings.LANGUAGES = (('xx', 'dummy language'), ('fr_FR.utf8', 'French (France), UTF8')) + settings.LANGUAGES = ( + ('xx', 'dummy language'), + ('fr_FR.utf8', 'French (France), UTF8'), + ('bs-Cyrl-BA', u'Bosnian (Cyrillic) (Bosnia and Herzegovina)') + ) self.__session_engine = settings.SESSION_ENGINE self.__storage_class = rosetta_settings.STORAGE_CLASS @@ -709,6 +702,11 @@ class RosettaTestCase(TestCase): # cleanup os.chmod(self.dest_file, 420) # 0644 + def test_36_issue_142_complex_locales(self): + r = self.client.get(reverse('rosetta-pick-file') + '?filter=all') + r = self.client.get(reverse('rosetta-pick-file')) + self.assertTrue(os.path.normpath('locale/bs-Cyrl-BA/LC_MESSAGES/django.po') in str(r.content)) + # Stubbed access control function def no_access(user): diff --git a/rosetta/tests/urls.py b/rosetta/tests/urls.py index f5cfe8b..9e8c0b2 100644 --- a/rosetta/tests/urls.py +++ b/rosetta/tests/urls.py @@ -4,7 +4,8 @@ except ImportError: from django.conf.urls.defaults import patterns, include, url -urlpatterns = patterns('', - url(r'^rosetta/',include('rosetta.urls')), - url(r'^admin/$','rosetta.tests.views.dummy', name='dummy-login') +urlpatterns = patterns( + '', + url(r'^rosetta/', include('rosetta.urls')), + url(r'^admin/$', 'rosetta.tests.views.dummy', name='dummy-login') ) diff --git a/rosetta/tests/views.py b/rosetta/tests/views.py index 9bc5b73..e213c44 100644 --- a/rosetta/tests/views.py +++ b/rosetta/tests/views.py @@ -1,3 +1,2 @@ def dummy(request): pass - diff --git a/testproject/locale/bs-Cyrl-BA/LC_MESSAGES/django.po b/testproject/locale/bs-Cyrl-BA/LC_MESSAGES/django.po new file mode 100644 index 0000000..5d9c151 --- /dev/null +++ b/testproject/locale/bs-Cyrl-BA/LC_MESSAGES/django.po @@ -0,0 +1,34 @@ +# 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 , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-09-14 02:28-0500\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" + +#: templates/test.html:3 +msgid "Some text to translate" +msgstr "" + +#: templates/test.html:5 +#, python-format +msgid "" +"\n" +"one bottle of beer on the wall\n" +msgid_plural "" +"\n" +"%(num_bottles)s bottles of beer on the wall\n" +msgstr[0] "" +msgstr[1] "" diff --git a/testproject/locale/fr/LC_MESSAGES/django.po b/testproject/locale/fr/LC_MESSAGES/django.po index 41ed440..5d9c151 100644 --- a/testproject/locale/fr/LC_MESSAGES/django.po +++ b/testproject/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-04-30 14:37+0200\n" +"POT-Creation-Date: 2015-09-14 02:28-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/testproject/locale/fr_FR.utf8/LC_MESSAGES/django.po b/testproject/locale/fr_FR.utf8/LC_MESSAGES/django.po index 41ed440..5d9c151 100644 --- a/testproject/locale/fr_FR.utf8/LC_MESSAGES/django.po +++ b/testproject/locale/fr_FR.utf8/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-04-30 14:37+0200\n" +"POT-Creation-Date: 2015-09-14 02:28-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/testproject/locale/xx/LC_MESSAGES/django.mo b/testproject/locale/xx/LC_MESSAGES/django.mo deleted file mode 100644 index 94e7c3878e136596caf6593c923935ffddcc45f3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1498 zcmdT@%aYng6jc%@3zn(ME{op8Wml?+S|EhvVPXX0VGBlp1`r!nkJJKzq{gj>#nj|8 z@&n#`>y4LLWRYE}vds_VC(?q%{)Xx5+vnb+(^seU`1{)@zY2VO!{d7%W>xUFOGuf zwvn+5=AmiPvOALZjR5r}tI=4va6nvTlDKm>Q*gXUsxkD_unHLNZ?^c=lu-u8kBMqrV#Fxdk1IBiRh({|%=+HMLZ zS?6-jT4lCgwp3q&O0Ep*-wTpeaQG&!7vwPc~7>Vl|u6#NSonZ{I z<0`M#$5M5JbzglA71@tQsIZHhLV7EW(v4-R_qj6hi~MN8H`AS5(zdk^dgft{4mZu& zZLGI@n-N(_x;K0)C62w%l(91PbhDpNC#rS4E38@8hzPPs`TzGVi-N`Io_HA?`*2BE z8q!1qbDEMY!?ig%QkKC3k29hHNfcFxL?|JEBuzp; zik#s>I44C|HT|SR5)@@9DF8J!S*@8k&7jS2l14bAOalO1VLuL&m*=(a(fFE+l5LK+ z1lk108W=E=csp=qnlGcUPTBUlHW^Qh&;C(eto3M;k%ad?9l5`Zl-WKW<@!}5gbq!ry59(=Q8ayUVuy5d6slK2>c90 zz%T!R#Osa(o<2RNSDj{+KC5W)3W?z1;mlVW@j2gv_#WwbZT;y95Fg&A=bQU`erO8W a\n" "Language-Team: French \n" @@ -35,12 +35,6 @@ msgstr[0] "" msgstr[1] "" msgstr[2] "" -#. This is a contextual comment -#: templates/test.html:3 -msgid "Some text to translate" -msgstr "" - - #~ msgid "" #~ "0_81EhfRiLPoxAH5j3f1D2P33S_-" #~ "Fe_7Mn_R_t9V8Bysr01xWAgvVEyyA190oYYTnzJCBucLBWKiqaAIjWAvQ3ZfrbCkDRe02iESoGhHEIBmmDI49SY6cQQk0AxGoB-" diff --git a/testproject/settings.py b/testproject/settings.py index 88b19c6..4d51cfe 100644 --- a/testproject/settings.py +++ b/testproject/settings.py @@ -60,11 +60,13 @@ MIDDLEWARE_CLASSES = ( ) LANGUAGES = ( + ('bs-Cyrl-BA', u'Bosnian (Cyrillic) (Bosnia and Herzegovina)'), ('ja', u'日本語'), ('xx', u'XXXXX'), ('fr', u'French'), ('fr_FR.utf8', u'French (France), UTF8'), ) + LOCALE_PATHS = [ os.path.join(PROJECT_PATH, 'locale'), ]