1#!/usr/bin/env python
2import os
3import subprocess
4import sys
5
6if len(sys.argv) < 3:
7    print("usage: ./compile_translations <program-name> <po directory>")
8    sys.exit(1)
9
10po_dir = sys.argv[-1]
11prg_name = sys.argv[-2]
12
13
14po_files = []
15for dirpath, _dirnames, filenames in os.walk(po_dir):
16    for file in filenames:
17        if file.split(".")[-1] == "po":
18            po_files.append(os.path.join(dirpath, file))
19
20for po in po_files:
21    lang = po.split("/")[-1]
22    print("Compiling for Locale: " + "".join(lang.split(".")[:-1]))
23    lang = lang.split("-")[-1]
24    lang = lang.split(".")[0]
25    lang = lang.strip()
26    if not lang:
27        continue
28
29    lang_dir = os.path.join("share/locale", lang)
30
31    if not os.path.isdir(lang_dir):
32        os.mkdir(lang_dir)
33
34    lang_lc_dir = os.path.join(lang_dir, "LC_MESSAGES")
35    if not os.path.isdir(lang_lc_dir):
36        os.mkdir(lang_lc_dir)
37
38    cmd = ["msgfmt", po, "-o", os.path.join(lang_lc_dir, "caffeine.mo")]
39
40    output = subprocess.check_output(cmd)
41