Skip to contentSkip to conversation

gui: Make sure sepolicy calls are translated properly

PATCH In review Vit Mojzis 1 participant 2 messages May 3, 2022 – May 4, 2022 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 gui: Make sure sepolicy calls are translated properly

The policy is generated using sepolicy.generate, but since its translations are in a different translation domain (selinux-python as opposed to selinux-gui), the confirmation dialog is not translated.

- Add selinux-python as a fallback translation domain
- Set the whole "generate()" confirmation as translatable
- Drop "codeset" parameter since it is deprecated

---
 gui/polgengui.py                     | 7 +++++--
 python/sepolicy/sepolicy/generate.py | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)
gui/polgengui.py +5 -2
index 01f541ba..dcd5df47 100644
@@ -69,10 +69,13 @@ try:
     kwargs = {}
     if sys.version_info < (3,):
         kwargs['unicode'] = True
-    gettext.install(PROGNAME,
+    t = gettext.translation(PROGNAME,
                     localedir="/usr/share/locale",
-                    codeset='utf-8',
                     **kwargs)
+    t.install()
+    t.add_fallback(gettext.translation("selinux-python",
+                    localedir="/usr/share/locale",
+                    **kwargs))
 except:
     try:
         import builtins
python/sepolicy/sepolicy/generate.py +1 -1
index 43180ca6..42d52109 100644
@@ -1372,7 +1372,7 @@ Warning %s does not exist
         fd.close()
 
     def generate(self, out_dir=os.getcwd()):
-        out = "Created the following files:\n"
+        out = _("Created the following files:\n")
         out += "%s # %s\n" % (self.write_te(out_dir), _("Type Enforcement file"))
         out += "%s # %s\n" % (self.write_if(out_dir), _("Interface file"))
         out += "%s # %s\n" % (self.write_fc(out_dir), _("File Contexts file"))
Signature · 1 line
2.35.1
author
#1 lore raw

Hello,
please disregard this patch. I am working on an improved solution for the issue based on module namespaces.

Sorry for the noise.

Quoted 47 lines · Vit Mojzis

The policy is generated using sepolicy.generate, but since its translations are in a different translation domain (selinux-python as opposed to selinux-gui), the confirmation dialog is not translated.

- Add selinux-python as a fallback translation domain
- Set the whole "generate()" confirmation as translatable
- Drop "codeset" parameter since it is deprecated

---
  gui/polgengui.py                     | 7 +++++--
  python/sepolicy/sepolicy/generate.py | 2 +-
  2 files changed, 6 insertions(+), 3 deletions(-)
gui/polgengui.py +5 -2
index 01f541ba..dcd5df47 100644
@@ -69,10 +69,13 @@ try:
      kwargs = {}
      if sys.version_info < (3,):
          kwargs['unicode'] = True
-    gettext.install(PROGNAME,
+    t = gettext.translation(PROGNAME,
                      localedir="/usr/share/locale",
-                    codeset='utf-8',
                      **kwargs)
+    t.install()
+    t.add_fallback(gettext.translation("selinux-python",
+                    localedir="/usr/share/locale",
+                    **kwargs))
  except:
      try:
          import builtins
python/sepolicy/sepolicy/generate.py +1 -1
index 43180ca6..42d52109 100644
@@ -1372,7 +1372,7 @@ Warning %s does not exist
          fd.close()
 
      def generate(self, out_dir=os.getcwd()):
-        out = "Created the following files:\n"
+        out = _("Created the following files:\n")
          out += "%s # %s\n" % (self.write_te(out_dir), _("Type Enforcement file"))
          out += "%s # %s\n" % (self.write_if(out_dir), _("Interface file"))
          out += "%s # %s\n" % (self.write_fc(out_dir), _("File Contexts file"))