[03/14] util/gen_xmlpool: Add a --meson switch

Submitted by Dylan Baker on Oct. 26, 2018, 5:23 p.m.

Details

Message ID 20181026172343.16933-4-dylan@pnwbakers.com
State New
Headers show
Series "translations updates" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Dylan Baker Oct. 26, 2018, 5:23 p.m.
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(-)

Patch hide | download patch | download mbox

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))