[mousetrap/gnome3-wip: 163/240] Automatically compile locales on install



commit 37a2962b10acaa3a26730b6913563b8f38d33fc0
Author: Kevin Brown <kevin kevinbrown in>
Date:   Wed Jun 25 18:40:45 2014 -0400

    Automatically compile locales on install

 MANIFEST.in |    1 +
 setup.py    |   32 +++++++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/MANIFEST.in b/MANIFEST.in
index be54547..e5bd24f 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -3,3 +3,4 @@ recursive-include src/mousetrap/locale *
 recursive-include src/mousetrap/haars *
 recursive-exclude * __pycache__
 recursive-exclude * *.py[co]
+recursive-exclude * *.mo
diff --git a/setup.py b/setup.py
index 835ed22..8f35585 100644
--- a/setup.py
+++ b/setup.py
@@ -98,7 +98,37 @@ The installation not work as expected without this dependency.
 class InstallCommand(install):
 
     def run(self):
-        print "Compiling language files..."
+        from subprocess import Popen
+
+        sys.stdout.write("Compiling locale files...\n")
+
+        program = "msgfmt"
+
+        LOCALE_PATH = "src/mousetrap/locale"
+
+        root, directories, files = os.walk(LOCALE_PATH).next()
+
+        language_codes = directories
+
+        for language_code in language_codes:
+            message_file = os.path.join(LOCALE_PATH, language_code, "LC_MESSAGES", "mousetrap.po")
+            compiled_file = os.path.join(LOCALE_PATH, language_code, "LC_MESSAGES", "mousetrap.mo")
+
+            arguments = [message_file, "--output-file", compiled_file]
+
+            sys.stdout.write("Compiling %s locale" % language_code)
+
+            command = [program] + arguments
+
+            process = Popen(command)
+
+            output, errors = process.communicate()
+            status_code = process.returncode
+
+            if status_code == 0:
+                sys.stdout.write(" [OK]\n")
+            else:
+                sys.stdout.write(" [FAIL]\n")
 
         install.run(self)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]