Support creating gettext files for new languages

Julien LepillerFri Aug 23 17:46:21+0200 2019

bea3c9f

Support creating gettext files for new languages

offlate/formats/gettext.py

1717
1818
import polib
1919
import datetime
20+
import os.path
2021
from dateutil.tz import tzlocal
2122
from .entry import POEntry
2223
2324
class GettextFormat:
2425
    def __init__(self, conf):
25-
        self.po = polib.pofile(conf["file"])
26+
        self.pofilename = conf["file"]
27+
        if os.path.isfile(conf["file"]):
28+
            self.po = polib.pofile(conf["file"])
29+
        else:
30+
            self.po = polib.pofile(conf["pot"])
2631
        self.pot = polib.pofile(conf["pot"])
2732
        self.conf = conf
2833

3540
        self.po.metadata['Last-Translator'] = self.conf['fullname']
3641
        self.po.metadata['Language'] = self.conf['lang']
3742
        self.po.metadata['X-Generator'] = 'Offlate ' + self.conf['version']
38-
        self.po.save()
43+
        self.po.save(self.pofilename)
3944
4045
    def merge(self, older, callback):
4146
        older.po.merge(self.pot)