[Mesa-dev] [PATCH 03/14] util/gen_xmlpool: Add a --meson switch
Dylan Baker
dylan at pnwbakers.com
Fri Oct 26 17:23:32 UTC 2018
Meson won't put the .gmo files in the layout that python's
gettext.translation() expects, so we need to handle them differently,
this switch allows the script to load the files as meson lays them out
v2: - Handle OSError as well as IOError, since that's what will happen
in the meson case if the file doesn't exist
- remove leftover debug code
---
src/util/xmlpool/gen_xmlpool.py | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py
index b40f295738e..e83e689de47 100644
--- a/src/util/xmlpool/gen_xmlpool.py
+++ b/src/util/xmlpool/gen_xmlpool.py
@@ -8,17 +8,18 @@
#
from __future__ import print_function
-
import argparse
-import io
-import sys
import gettext
+import io
+import os
import re
+import sys
parser = argparse.ArgumentParser()
parser.add_argument('template')
parser.add_argument('localedir')
parser.add_argument('languages', nargs='*')
+parser.add_argument('--meson', action='store_true')
args = parser.parse_args()
if sys.version_info < (3, 0):
@@ -166,8 +167,13 @@ def expandMatches (matches, translations, end=None):
translations = [("en", gettext.NullTranslations())]
for lang in args.languages:
try:
- trans = gettext.translation ("options", args.localedir, [lang])
- except IOError:
+ if args.meson:
+ filename = os.path.join(args.localedir, '{}.gmo'.format(lang))
+ with io.open(filename, 'rb') as f:
+ trans = gettext.GNUTranslations(f)
+ else:
+ trans = gettext.translation ("options", args.localedir, [lang])
+ except (IOError, OSError):
sys.stderr.write ("Warning: language '%s' not found.\n" % lang)
continue
translations.append ((lang, trans))
--
2.19.1
More information about the mesa-dev
mailing list