Repository: ckan/ckan

Issue:
Titles from licenses from a custom file are not translated
Looks like this:

![screenshot_2018-12-18 creeu un conjunt de dades - ckan 1](https://user-images.githubusercontent.com/200230/50148656-59c81180-02b9-11e9-8d20-5bc43f4a75c2.png)


Should look like this:

![screenshot_2018-12-18 creeu un conjunt de dades - ckan](https://user-images.githubusercontent.com/200230/50148662-5d5b9880-02b9-11e9-9995-73ba8fc996f2.png)





Discussion:

Resolving patch:
diff --git a/ckan/model/license.py b/ckan/model/license.py
--- a/ckan/model/license.py
+++ b/ckan/model/license.py
@@ -6,7 +6,7 @@
 
 from ckan.common import config
 from paste.deploy.converters import asbool
-from six import text_type
+from six import text_type, string_types
 
 from ckan.common import _, json
 import ckan.lib.maintain as maintain
@@ -126,6 +126,11 @@ def load_licenses(self, license_url):
         except Exception as inst:
             msg = "Couldn't read response from licenses service %r: %s" % (response_body, inst)
             raise Exception(inst)
+        for license in license_data:
+            if isinstance(license, string_types):
+                license = license_data[license]
+            if license.get('title'):
+                license['title'] = _(license['title'])
         self._create_license_list(license_data, license_url)
 
     def _create_license_list(self, license_data, license_url=''):


Test patch:
diff --git a/ckan/tests/model/licenses.v1 b/ckan/tests/model/licenses.v1
--- a/ckan/tests/model/licenses.v1
+++ b/ckan/tests/model/licenses.v1
@@ -13,5 +13,19 @@
     "domain_software": "False",
     "id": "cc-by"
 
-}
+},
+  {
+    "domain_content": true,
+    "domain_data": false,
+    "domain_software": false,
+    "family": "",
+    "id": "other-open",
+    "is_generic": true,
+    "maintainer": "",
+    "od_conformance": "approved",
+    "osd_conformance": "not reviewed",
+    "status": "active",
+    "title": "Other (Open)",
+    "url": ""
+  }
 ]
diff --git a/ckan/tests/model/licenses.v2 b/ckan/tests/model/licenses.v2
--- a/ckan/tests/model/licenses.v2
+++ b/ckan/tests/model/licenses.v2
@@ -12,6 +12,19 @@
     "status": "active",
     "title": "Creative Commons Attribution 4.0",
     "url": "https://creativecommons.org/licenses/by/4.0/"
-
+},
+"other-open": {
+    "domain_content": true,
+    "domain_data": false,
+    "domain_software": false,
+    "family": "",
+    "id": "other-open",
+    "is_generic": true,
+    "maintainer": "",
+    "od_conformance": "approved",
+    "osd_conformance": "not reviewed",
+    "status": "active",
+    "title": "Other (Open)",
+    "url": ""
 }
 }
diff --git a/ckan/tests/model/test_license.py b/ckan/tests/model/test_license.py
--- a/ckan/tests/model/test_license.py
+++ b/ckan/tests/model/test_license.py
@@ -6,7 +6,11 @@
 from ckan.common import config
 
 from ckan.model.license import LicenseRegister
-from ckan.tests import helpers
+from ckan.tests import helpers, factories
+
+assert_in = helpers.assert_in
+
+this_dir = os.path.dirname(os.path.realpath(__file__))
 
 
 class TestLicenseRegister(object):
@@ -24,11 +28,8 @@ def test_default_register_has_basic_properties_of_a_license(self):
         assert_equal(license.isopen(), True)
         assert_equal(license.title, 'Creative Commons Attribution')
 
+    @helpers.change_config('licenses_group_url', 'file:///%s/licenses.v1' % this_dir)
     def test_import_v1_style_register(self):
-        this_dir = os.path.dirname(os.path.realpath(__file__))
-        # v1 is used by CKAN so far
-        register_filepath = '%s/licenses.v1' % this_dir
-        config['licenses_group_url'] = 'file:///%s' % register_filepath
         reg = LicenseRegister()
 
         license = reg['cc-by']
@@ -37,11 +38,9 @@ def test_import_v1_style_register(self):
         assert_equal(license.isopen(), True)
         assert_equal(license.title, 'Creative Commons Attribution')
 
+    # v2 is used by http://licenses.opendefinition.org in recent times
+    @helpers.change_config('licenses_group_url', 'file:///%s/licenses.v2' % this_dir)
     def test_import_v2_style_register(self):
-        this_dir = os.path.dirname(os.path.realpath(__file__))
-        # v2 is used by http://licenses.opendefinition.org in recent times
-        register_filepath = '%s/licenses.v2' % this_dir
-        config['licenses_group_url'] = 'file:///%s' % register_filepath
         reg = LicenseRegister()
 
         license = reg['CC-BY-4.0']
@@ -50,6 +49,26 @@ def test_import_v2_style_register(self):
         assert_equal(license.isopen(), True)
         assert_equal(license.title, 'Creative Commons Attribution 4.0')
 
+    @helpers.change_config('licenses_group_url', 'file:///%s/licenses.v1' % this_dir)
+    @helpers.change_config('ckan.locale_default', 'ca')
+    def test_import_v1_style_register_i18n(self):
+
+        sysadmin = factories.Sysadmin()
+        app = helpers._get_test_app()
+
+        resp = app.get('/dataset/new', extra_environ={'REMOTE_USER': str(sysadmin['name'])})
+        assert_in('Altres (Oberta)', resp.body)
+
+    @helpers.change_config('licenses_group_url', 'file:///%s/licenses.v2' % this_dir)
+    @helpers.change_config('ckan.locale_default', 'ca')
+    def test_import_v2_style_register_i18n(self):
+
+        sysadmin = factories.Sysadmin()
+        app = helpers._get_test_app()
+
+        resp = app.get('/dataset/new', extra_environ={'REMOTE_USER': str(sysadmin['name'])})
+        assert_in('Altres (Oberta)', resp.body)
+
 
 class TestLicense:
     def test_access_via_attribute(self):