← Back to team overview

checkbox-dev team mailing list archive

[PATCH 04/13] plainbox:secure:providers: add Provider1.locale_dir

 

This patch adds a way to associate locale directory with each provider.
This directory can be fed to bindtextdomain(). Using this together
allows plainbox to load translation catalogs for any provider without
any hard-coded assumptions.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@xxxxxxxxxxxxx>
---
 plainbox/plainbox/impl/secure/providers/test_v1.py | 16 +++++++++++++++-
 plainbox/plainbox/impl/secure/providers/v1.py      | 19 ++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/plainbox/plainbox/impl/secure/providers/test_v1.py b/plainbox/plainbox/impl/secure/providers/test_v1.py
index 091567e..d0f14bc 100644
--- a/plainbox/plainbox/impl/secure/providers/test_v1.py
+++ b/plainbox/plainbox/impl/secure/providers/test_v1.py
@@ -492,11 +492,12 @@ class Provider1Tests(TestCase):
     DESCRIPTION = "description"
     SECURE = True
     GETTEXT_DOMAIN = "domain"
+    LOCALE_DIR = "locale-dir"
 
     def setUp(self):
         self.provider = Provider1(
             self.BASE_DIR, self.NAME, self.VERSION, self.DESCRIPTION,
-            self.SECURE, self.GETTEXT_DOMAIN)
+            self.SECURE, self.GETTEXT_DOMAIN, self.LOCALE_DIR)
 
     def test_repr(self):
         self.assertEqual(
@@ -545,6 +546,19 @@ class Provider1Tests(TestCase):
         """
         self.assertEqual(self.provider.whitelists_dir, "base-dir/whitelists")
 
+    def test_locale_dir(self):
+        """
+        Verify that Provider1.locale_dir attribute is set correctly
+        """
+        self.assertEqual(self.provider.locale_dir, self.LOCALE_DIR)
+
+    def test_locale_dir_rw(self):
+        """
+        Verify that Provider1.locale_dir attribute is can be reset
+        """
+        self.provider.locale_dir = "new-locale-dir"
+        self.assertEqual(self.provider.locale_dir, "new-locale-dir")
+
     def test_CHECKBOX_SHARE(self):
         """
         Verify that Provider1.CHECKBOX_SHARE is always equal to base_dir
diff --git a/plainbox/plainbox/impl/secure/providers/v1.py b/plainbox/plainbox/impl/secure/providers/v1.py
index d756f8c..68ae238 100644
--- a/plainbox/plainbox/impl/secure/providers/v1.py
+++ b/plainbox/plainbox/impl/secure/providers/v1.py
@@ -135,7 +135,7 @@ class Provider1(IProvider1, IProviderBackend1):
     """
 
     def __init__(self, base_dir, name, version, description, secure,
-                 gettext_domain=None):
+                 gettext_domain=None, locale_dir=None):
         """
         Initialize the provider with the associated base directory.
 
@@ -145,6 +145,7 @@ class Provider1(IProvider1, IProviderBackend1):
         normal operation.
         """
         self._base_dir = base_dir
+        self._locale_dir = locale_dir
         self._name = name
         self._version = version
         self._description = description
@@ -217,6 +218,22 @@ class Provider1(IProvider1, IProviderBackend1):
         return os.path.join(self._base_dir, "whitelists")
 
     @property
+    def locale_dir(self):
+        """
+        absolute path of the directory with locale data
+
+        The value is applicable as argument bindtextdomain()
+
+        The returned value may either be a custom directory, assigned to this
+        property explicitly or None (default)
+        """
+        return self._locale_dir
+
+    @locale_dir.setter
+    def locale_dir(self, new_value):
+        self._locale_dir = new_value
+
+    @property
     def CHECKBOX_SHARE(self):
         """
         Return the required value of CHECKBOX_SHARE environment variable.
-- 
1.9.0



References