| 1 |
#!/usr/bin/env python3 |
| 2 |
import os |
| 3 |
import sys |
| 4 |
|
| 5 |
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 6 |
sys.path.insert(0, root) |
| 7 |
|
| 8 |
from DisplayCAL import jsondict |
| 9 |
from DisplayCAL.util_list import natsort |
| 10 |
from DisplayCAL.util_os import safe_glob |
| 11 |
|
| 12 |
|
| 13 |
def convert(infilename): |
| 14 |
dictin = jsondict.JSONDict(infilename) |
| 15 |
dictin.load() |
| 16 |
|
| 17 |
outfilename = os.path.splitext(infilename)[0] + ".yaml" |
| 18 |
with open(outfilename, "wb") as outfile: |
| 19 |
for key in natsort(dictin.keys(), False): |
| 20 |
outfile.write('"%s": |-\n' % key.encode("UTF-8")) |
| 21 |
for line in dictin[key].split("\n"): |
| 22 |
# Do not use splitlines, returns empty list for empty string |
| 23 |
outfile.write(" %s\n" % line.encode("UTF-8")) |
| 24 |
|
| 25 |
|
| 26 |
if __name__ == "__main__": |
| 27 |
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]: |
| 28 |
print("Usage: %s" % os.path.basename(sys.argv[0])) |
| 29 |
print("Converts translation JSON files to YAML files") |
| 30 |
else: |
| 31 |
for langfile in safe_glob(os.path.join(root, "DisplayCAL", "lang", "*.json")): |
| 32 |
convert(langfile) |