gettext: handle unsupported languages properly
PATCH 1/1 gettext: handle unsupported languages properly
With "fallback=True" gettext.translation behaves the same as gettext.install and uses NullTranslations in case the translation file for given language was not found (as opposed to throwing an exception).
Fixes:
# LANG is set to any "unsupported" language, e.g. en_US.UTF-8
$ chcat --help
Traceback (most recent call last):
File "/usr/bin/chcat", line 39, in <module>
t = gettext.translation(PROGNAME,
File "/usr/lib64/python3.9/gettext.py", line 592, in translation
raise FileNotFoundError(ENOENT,
FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'--- gui/booleansPage.py | 3 ++- gui/domainsPage.py | 3 ++- gui/fcontextPage.py | 3 ++- gui/loginsPage.py | 3 ++- gui/modulesPage.py | 3 ++- gui/polgengui.py | 3 ++- gui/portsPage.py | 3 ++- gui/semanagePage.py | 3 ++- gui/statusPage.py | 3 ++- gui/system-config-selinux.py | 3 ++- gui/usersPage.py | 3 ++- python/chcat/chcat | 5 +++-- python/semanage/semanage | 3 ++- python/semanage/seobject.py | 3 ++- python/sepolgen/src/sepolgen/sepolgeni18n.py | 4 +++- python/sepolicy/sepolicy.py | 3 ++- python/sepolicy/sepolicy/__init__.py | 3 ++- python/sepolicy/sepolicy/generate.py | 3 ++- python/sepolicy/sepolicy/gui.py | 3 ++- python/sepolicy/sepolicy/interface.py | 3 ++- sandbox/sandbox | 3 ++- 21 files changed, 44 insertions(+), 22 deletions(-)
gui/booleansPage.py +2 -1
@@ -46,7 +46,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/domainsPage.py +2 -1
@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/fcontextPage.py +2 -1
@@ -55,7 +55,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/loginsPage.py +2 -1
@@ -37,7 +37,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/modulesPage.py +2 -1
@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/polgengui.py +2 -1
@@ -71,7 +71,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/portsPage.py +2 -1
@@ -43,7 +43,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/semanagePage.py +2 -1
@@ -30,7 +30,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/statusPage.py +2 -1
@@ -43,7 +43,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/system-config-selinux.py +2 -1
@@ -53,7 +53,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
gui/usersPage.py +2 -1
@@ -37,7 +37,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/chcat/chcat +3 -2
@@ -38,9 +38,10 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext -except ImportError: +except: try: import builtins builtins.__dict__['_'] = str
python/semanage/semanage +2 -1
@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/semanage/seobject.py +2 -1
@@ -42,7 +42,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/sepolgen/src/sepolgen/sepolgeni18n.py +3 -1
@@ -19,7 +19,9 @@ try: import gettext - t = gettext.translation( 'selinux-python' ) + t = gettext.translation("selinux-python", + localedir="/usr/share/locale", + fallback=True) _ = t.gettext except: def _(str):
python/sepolicy/sepolicy.py +2 -1
@@ -36,7 +36,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/sepolicy/sepolicy/__init__.py +2 -1
@@ -31,7 +31,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/sepolicy/sepolicy/generate.py +2 -1
@@ -56,7 +56,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/sepolicy/sepolicy/gui.py +2 -1
@@ -49,7 +49,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
python/sepolicy/sepolicy/interface.py +2 -1
@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
sandbox/sandbox +2 -1
@@ -45,7 +45,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
Signature · 1 line
2.35.3
Quoted 199 lines · Vit Mojzis
With "fallback=True" gettext.translation behaves the same as gettext.install and uses NullTranslations in case the translation file for given language was not found (as opposed to throwing an exception).
Fixes:
# LANG is set to any "unsupported" language, e.g. en_US.UTF-8$ chcat --help Traceback (most recent call last): File "/usr/bin/chcat", line 39, in <module> t = gettext.translation(PROGNAME, File "/usr/lib64/python3.9/gettext.py", line 592, in translation raise FileNotFoundError(ENOENT, FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'Signed-off-by Vit Mojzis <[email protected]>--- gui/booleansPage.py | 3 ++- gui/domainsPage.py | 3 ++- gui/fcontextPage.py | 3 ++- gui/loginsPage.py | 3 ++- gui/modulesPage.py | 3 ++- gui/polgengui.py | 3 ++- gui/portsPage.py | 3 ++- gui/semanagePage.py | 3 ++- gui/statusPage.py | 3 ++- gui/system-config-selinux.py | 3 ++- gui/usersPage.py | 3 ++- python/chcat/chcat | 5 +++-- python/semanage/semanage | 3 ++- python/semanage/seobject.py | 3 ++- python/sepolgen/src/sepolgen/sepolgeni18n.py | 4 +++- python/sepolicy/sepolicy.py | 3 ++- python/sepolicy/sepolicy/__init__.py | 3 ++- python/sepolicy/sepolicy/generate.py | 3 ++- python/sepolicy/sepolicy/gui.py | 3 ++- python/sepolicy/sepolicy/interface.py | 3 ++- sandbox/sandbox | 3 ++- 21 files changed, 44 insertions(+), 22 deletions(-)gui/booleansPage.py +2
-1@@ -46,7 +46,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/domainsPage.py +2
-1@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/fcontextPage.py +2
-1@@ -55,7 +55,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/loginsPage.py +2
-1@@ -37,7 +37,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/modulesPage.py +2
-1@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/polgengui.py +2
-1@@ -71,7 +71,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/portsPage.py +2
-1@@ -43,7 +43,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/semanagePage.py +2
-1@@ -30,7 +30,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/statusPage.py +2
-1@@ -43,7 +43,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/system-config-selinux.py +2
-1@@ -53,7 +53,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:gui/usersPage.py +2
-1@@ -37,7 +37,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/chcat/chcat +0
-0
python/chcat/chcat try: · line 44
Quoted 9 lines
python/chcat/chcat +3
-2@@ -38,9 +38,10 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext -except ImportError: +except:
Isn't the point of the overall change that gettext.translation() doesn't throw an exception anymore? So we don't need to handle OSError/IOError here once fallback=True. I see that this standardizes with the other call sites, but I wonder if standardizing on the more specific exceptions (or just leaving as is) wouldn't be better?
-Daniel
Quoted 130 lines
python/chcat/chcat +0
-0try: import builtins builtins.__dict__['_'] = strpython/semanage/semanage +2
-1@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/semanage/seobject.py +2
-1@@ -42,7 +42,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/sepolgen/src/sepolgen/sepolgeni18n.py +3
-1@@ -19,7 +19,9 @@ try: import gettext - t = gettext.translation( 'selinux-python' ) + t = gettext.translation("selinux-python", + localedir="/usr/share/locale", + fallback=True) _ = t.gettext except: def _(str):python/sepolicy/sepolicy.py +2
-1@@ -36,7 +36,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/sepolicy/sepolicy/__init__.py +2
-1@@ -31,7 +31,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/sepolicy/sepolicy/generate.py +2
-1@@ -56,7 +56,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/sepolicy/sepolicy/gui.py +2
-1@@ -49,7 +49,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:python/sepolicy/sepolicy/interface.py +2
-1@@ -38,7 +38,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:sandbox/sandbox +2
-1@@ -45,7 +45,8 @@ try: kwargs['unicode'] = True t = gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs) + **kwargs, + fallback=True) _ = t.gettext except: try:
Quoted 203 lines · Daniel Burgener
Quoted 202 lines · Vit Mojzis
With "fallback=True" gettext.translation behaves the same as gettext.install and uses NullTranslations in case the translation file for given language was not found (as opposed to throwing an exception).
Fixes:
# LANG is set to any "unsupported" language, e.g. en_US.UTF-8$ chcat --help Traceback (most recent call last): File "/usr/bin/chcat", line 39, in <module> t = gettext.translation(PROGNAME, File "/usr/lib64/python3.9/gettext.py", line 592, in translation raise FileNotFoundError(ENOENT, FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'Signed-off-by Vit Mojzis <[email protected]>---
gui/booleansPage.py | 3 ++- gui/domainsPage.py | 3 ++- gui/fcontextPage.py | 3 ++- gui/loginsPage.py | 3 ++- gui/modulesPage.py | 3 ++- gui/polgengui.py | 3 ++- gui/portsPage.py | 3 ++- gui/semanagePage.py | 3 ++- gui/statusPage.py | 3 ++- gui/system-config-selinux.py | 3 ++- gui/usersPage.py | 3 ++- python/chcat/chcat | 5 +++-- python/semanage/semanage | 3 ++- python/semanage/seobject.py | 3 ++-python/sepolgen/src/sepolgen/sepolgeni18n.py| 4 +++- python/sepolicy/sepolicy.py | 3 ++- python/sepolicy/sepolicy/__init__.py | 3 ++- python/sepolicy/sepolicy/generate.py | 3 ++- python/sepolicy/sepolicy/gui.py | 3 ++- python/sepolicy/sepolicy/interface.py | 3 ++- sandbox/sandbox | 3 ++-21 files changed, 44 insertions(+), 22 deletions(-)gui/booleansPage.py +0
-0@@ -46,7 +46,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/domainsPage.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/fcontextPage.py +0
-0@@ -55,7 +55,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/loginsPage.py +0
-0@@ -37,7 +37,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/modulesPage.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/polgengui.py +0
-0@@ -71,7 +71,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/portsPage.py +0
-0@@ -43,7 +43,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/semanagePage.py +0
-0@@ -30,7 +30,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/statusPage.py +0
-0@@ -43,7 +43,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/system-config-selinux.py +0
-0@@ -53,7 +53,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/usersPage.py +0
-0@@ -37,7 +37,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/chcat/chcat +0
-0@@ -38,9 +38,10 @@ try:kwargs['unicode'] = True
t = gettext.translation(PROGNAME, localedir="/usr/share/locale",
Quoted 8 lines
python/chcat/chcat try: · line 44
Quoted 6 lines
- **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettextpython/chcat/chcat +1
-1-except ImportError: +except:Isn't the point of the overall change that
gettext.translation()doesn't throw an exception anymore? So we don't need to handle OSError/IOError here once fallback=True. I see that this standardizes with the other call sites, but I wonder if standardizing on the more specific exceptions (or just leaving as is) wouldn't be better?
Yes, we do not need to handle OSError/IOError exceptions any more.
I agree that standardizing on the more specific exception handling would be more proper. However, translation handling is probably the least important feature of this tool (most people probably use it in English and those who don't wish they did) -- we don't want people to be unable to use the tool at all because of some translation issue and "catch all" exception handling is the easiest way to avoid that. As this bug showed, not settling on a single approach is probably the worst alternative (I tested the previous patch with multiple tools, but apparently missed the one that was different).
That being said, either approach is fine by me. Please let me know if I should change the patch. Vit
Quoted 133 lines
-Daniel
Quoted 129 lines
try:
import builtins
builtins.__dict__['_'] = strpython/semanage/semanage +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/semanage/seobject.py +0
-0@@ -42,7 +42,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolgen/src/sepolgen/sepolgeni18n.py +0
-0@@ -19,7 +19,9 @@try:
import gettext
- t =gettext.translation( 'selinux-python' )+ t = gettext.translation("selinux-python", + localedir="/usr/share/locale", + fallback=True)
_ = t.gettext
except:
def_(str):python/sepolicy/sepolicy.py +0
-0@@ -36,7 +36,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/__init__.py +0
-0@@ -31,7 +31,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/generate.py +0
-0@@ -56,7 +56,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/gui.py +0
-0@@ -49,7 +49,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/interface.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:sandbox/sandbox +0
-0@@ -45,7 +45,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:
Daniel Burgener
Reviewed-byQuoted 215 lines · Vit Mojzis
Quoted 203 lines · Daniel Burgener
Quoted 202 lines · Vit Mojzis
With "fallback=True" gettext.translation behaves the same as gettext.install and uses NullTranslations in case the translation file for given language was not found (as opposed to throwing an exception).
Fixes:
# LANG is set to any "unsupported" language, e.g. en_US.UTF-8$ chcat --help Traceback (most recent call last): File "/usr/bin/chcat", line 39, in <module> t = gettext.translation(PROGNAME, File "/usr/lib64/python3.9/gettext.py", line 592, in translation raise FileNotFoundError(ENOENT, FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'Signed-off-by Vit Mojzis <[email protected]>---
gui/booleansPage.py | 3 ++- gui/domainsPage.py | 3 ++- gui/fcontextPage.py | 3 ++- gui/loginsPage.py | 3 ++- gui/modulesPage.py | 3 ++- gui/polgengui.py | 3 ++- gui/portsPage.py | 3 ++- gui/semanagePage.py | 3 ++- gui/statusPage.py | 3 ++- gui/system-config-selinux.py | 3 ++- gui/usersPage.py | 3 ++- python/chcat/chcat | 5 +++-- python/semanage/semanage | 3 ++- python/semanage/seobject.py | 3 ++-python/sepolgen/src/sepolgen/sepolgeni18n.py| 4 +++- python/sepolicy/sepolicy.py | 3 ++- python/sepolicy/sepolicy/__init__.py | 3 ++- python/sepolicy/sepolicy/generate.py | 3 ++- python/sepolicy/sepolicy/gui.py | 3 ++- python/sepolicy/sepolicy/interface.py | 3 ++- sandbox/sandbox | 3 ++-21 files changed, 44 insertions(+), 22 deletions(-)gui/booleansPage.py +0
-0@@ -46,7 +46,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/domainsPage.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/fcontextPage.py +0
-0@@ -55,7 +55,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/loginsPage.py +0
-0@@ -37,7 +37,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/modulesPage.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/polgengui.py +0
-0@@ -71,7 +71,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/portsPage.py +0
-0@@ -43,7 +43,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/semanagePage.py +0
-0@@ -30,7 +30,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/statusPage.py +0
-0@@ -43,7 +43,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/system-config-selinux.py +0
-0@@ -53,7 +53,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/usersPage.py +0
-0@@ -37,7 +37,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/chcat/chcat +0
-0@@ -38,9 +38,10 @@ try:kwargs['unicode'] = True
t = gettext.translation(PROGNAME, localedir="/usr/share/locale",Quoted 8 lines
python/chcat/chcat try: · line 44
Quoted 6 lines
- **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettextpython/chcat/chcat +1
-1-except ImportError: +except:Isn't the point of the overall change that
gettext.translation()doesn't throw an exception anymore? So we don't need to handle OSError/IOError here once fallback=True. I see that this standardizes with the other call sites, but I wonder if standardizing on the more specific exceptions (or just leaving as is) wouldn't be better?
Quoted 6 lines
Yes, we do not need to handle OSError/IOError exceptions any more.
I agree that standardizing on the more specific exception handling would be more proper. However, translation handling is probably the least important feature of this tool (most people probably use it in English and those who don't wish they did) -- we don't want people to be unable to use the tool at all because of some translation issue and "catch all" exception handling is the easiest way to avoid that. As this bug showed, not settling on a single approach is probably the worst alternative (I tested the previous patch with multiple tools, but apparently missed the one that was different).That being said, either approach is fine by me. Please let me know if I should change the patch. Vit
Well, I'll leave questions of what you *should* do up to the maintainers, but I think as far as I'm concerned your point that we really don't want to fail hard on translations makes a lot of sense (and I definitely agree that inconsistency is a pretty bad alternative. So I'm on board with this approach. I was initially worried about "what if in some future version gettext adds an exception?", but to your point, we want the same fallback logic in that case, so the general except seems reasonable.
Quoted 134 lines
Quoted 134 lines
-Daniel
Quoted 129 lines
try:
import builtins
builtins.__dict__['_'] = strpython/semanage/semanage +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/semanage/seobject.py +0
-0@@ -42,7 +42,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolgen/src/sepolgen/sepolgeni18n.py +0
-0@@ -19,7 +19,9 @@try:
import gettext
- t =gettext.translation( 'selinux-python' )+ t = gettext.translation("selinux-python", + localedir="/usr/share/locale", + fallback=True)
_ = t.gettext
except:
def_(str):python/sepolicy/sepolicy.py +0
-0@@ -36,7 +36,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/__init__.py +0
-0@@ -31,7 +31,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/generate.py +0
-0@@ -56,7 +56,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/gui.py +0
-0@@ -49,7 +49,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/interface.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:sandbox/sandbox +0
-0@@ -45,7 +45,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:
Petr Lautrbach
Acked-byQuoted 245 lines · Daniel Burgener
Quoted 231 lines · Vit Mojzis
Quoted 208 lines · Daniel Burgener
Quoted 207 lines · Vit Mojzis
With "fallback=True" gettext.translation behaves the same as gettext.install and uses NullTranslations in case the translation file for given language was not found (as opposed to throwing an exception).
Fixes:
# LANG is set to any "unsupported" language, e.g. en_US.UTF-8$ chcat --help Traceback (most recent call last): File "/usr/bin/chcat", line 39, in <module> t = gettext.translation(PROGNAME, File "/usr/lib64/python3.9/gettext.py", line 592, in translation raise FileNotFoundError(ENOENT, FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'Signed-off-by Vit Mojzis <[email protected]>---
gui/booleansPage.py | 3 ++- gui/domainsPage.py | 3 ++- gui/fcontextPage.py | 3 ++- gui/loginsPage.py | 3 ++- gui/modulesPage.py | 3 ++- gui/polgengui.py | 3 ++- gui/portsPage.py | 3 ++- gui/semanagePage.py | 3 ++- gui/statusPage.py | 3 ++- gui/system-config-selinux.py | 3 ++- gui/usersPage.py | 3 ++- python/chcat/chcat | 5 +++-- python/semanage/semanage | 3 ++- python/semanage/seobject.py | 3 ++-python/sepolgen/src/sepolgen/sepolgeni18n.py| 4 +++- python/sepolicy/sepolicy.py | 3 ++- python/sepolicy/sepolicy/__init__.py | 3 ++- python/sepolicy/sepolicy/generate.py | 3 ++- python/sepolicy/sepolicy/gui.py | 3 ++- python/sepolicy/sepolicy/interface.py | 3 ++- sandbox/sandbox | 3 ++-21 files changed, 44 insertions(+), 22 deletions(-)gui/booleansPage.py +0
-0@@ -46,7 +46,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/domainsPage.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/fcontextPage.py +0
-0@@ -55,7 +55,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/loginsPage.py +0
-0@@ -37,7 +37,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/modulesPage.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/polgengui.py +0
-0@@ -71,7 +71,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/portsPage.py +0
-0@@ -43,7 +43,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/semanagePage.py +0
-0@@ -30,7 +30,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/statusPage.py +0
-0@@ -43,7 +43,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/system-config-selinux.py +0
-0@@ -53,7 +53,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:gui/usersPage.py +0
-0@@ -37,7 +37,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/chcat/chcat +0
-0@@ -38,9 +38,10 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettextQuoted 8 lines
python/chcat/chcat try: · line 44
Quoted 2 lines
python/chcat/chcat +1
-1-except ImportError: +except:Isn't the point of the overall change that
gettext.translation()doesn't throw an exception anymore? So we don't need to handle OSError/IOError here once fallback=True. I see that this standardizes with the other call sites, but I wonder if standardizing on the more specific exceptions (or just leaving as is) wouldn't be better?Yes, we do not need to handle OSError/IOError exceptions any more. I agree that standardizing on the more specific exception handling would be more proper. However, translation handling is probably the least important feature of this tool (most people probably use it in English and those who don't wish they did) -- we don't want people to be unable to use the tool at all because of some translation issue and "catch all" exception handling is the easiest way to avoid that.
As this bug showed, not settling on a single approach is probably the worst alternative (I tested the previous patch with multiple tools, but apparently missed the one that was different).Quoted 3 lines
That being said, either approach is fine by me. Please let me know if I should change the patch.
VitWell, I'll leave questions of what you *should* do up to the maintainers, but I think as far as I'm concerned your point that we really don't want to fail hard on translations makes a lot of sense (and I definitely agree that inconsistency is a pretty bad alternative. So I'm on board with this approach. I was initially worried about "what if in some future version gettext adds an exception?", but to your point, we want the same fallback logic in that case, so the general except seems reasonable.
Quoted 2 lines
Reviewed-by Daniel Burgener <[email protected]>
Thanks!
Quoted 139 lines
Quoted 139 lines
Quoted 139 lines
-Daniel
Quoted 134 lines
try:
import builtins
builtins.__dict__['_'] = strpython/semanage/semanage +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/semanage/seobject.py +0
-0@@ -42,7 +42,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolgen/src/sepolgen/sepolgeni18n.py +0
-0@@ -19,7 +19,9 @@try:
import gettext
- t =gettext.translation( 'selinux-python' )+ t = gettext.translation("selinux-python", + localedir="/usr/share/locale", + fallback=True)
_ = t.gettext
except:
def_(str):python/sepolicy/sepolicy.py +0
-0@@ -36,7 +36,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/__init__.py +0
-0@@ -31,7 +31,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/generate.py +0
-0@@ -56,7 +56,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/gui.py +0
-0@@ -49,7 +49,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:python/sepolicy/sepolicy/interface.py +0
-0@@ -38,7 +38,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:sandbox/sandbox +0
-0@@ -45,7 +45,8 @@ try:kwargs['unicode'] = True
t =gettext.translation(PROGNAME, localedir="/usr/share/locale", - **kwargs)
+ **kwargs,
+ fallback=True)
_ = t.gettext
except:
try:
Quoted 25 lines · Petr Lautrbach
Quoted 23 lines · Daniel Burgener
Quoted 22 lines · Vit Mojzis
Quoted 19 lines · Daniel Burgener
Quoted 18 lines · Vit Mojzis
With "fallback=True" gettext.translation behaves the same as gettext.install and uses NullTranslations in case the translation file for given language was not found (as opposed to throwing an exception).
Fixes:
# LANG is set to any "unsupported" language, e.g. en_US.UTF-8$ chcat --help Traceback (most recent call last): File "/usr/bin/chcat", line 39, in <module> t = gettext.translation(PROGNAME, File "/usr/lib64/python3.9/gettext.py", line 592, in translation raise FileNotFoundError(ENOENT, FileNotFoundError: [Errno 2] No translation file found for domain: 'selinux-python'Signed-off-by Vit Mojzis <[email protected]>---
[...]
Quoted 31 lines
Quoted 31 lines
Quoted 18 lines
Quoted 6 lines
Isn't the point of the overall change that
gettext.translation()doesn't throw an exception anymore? So we don't need to handle OSError/IOError here once fallback=True. I see that this standardizes with the other call sites, but I wonder if standardizing on the more specific exceptions (or just leaving as is) wouldn't be better?Yes, we do not need to handle OSError/IOError exceptions any more. I agree that standardizing on the more specific exception handling would be more proper. However, translation handling is probably the least important feature of this tool (most people probably use it in English and those who don't wish they did) -- we don't want people to be unable to use the tool at all because of some translation issue and "catch all" exception handling is the easiest way to avoid that.
As this bug showed, not settling on a single approach is probably the worst alternative (I tested the previous patch with multiple tools, but apparently missed the one that was different).Quoted 3 lines
That being said, either approach is fine by me. Please let me know if I should change the patch.
VitWell, I'll leave questions of what you *should* do up to the maintainers, but I think as far as I'm concerned your point that we really don't want to fail hard on translations makes a lot of sense (and I definitely agree that inconsistency is a pretty bad alternative. So I'm on board with this approach. I was initially worried about "what if in some future version gettext adds an exception?", but to your point, we want the same fallback logic in that case, so the general except seems reasonable.
Quoted 8 lines
Quoted 2 lines
Reviewed-by Daniel Burgener <[email protected]>Thanks!
Acked-by Petr Lautrbach <[email protected]>
Merged.