Support creating gettext files for new languages
offlate/formats/gettext.py
17 | 17 | ||
18 | 18 | import polib | |
19 | 19 | import datetime | |
20 | + | import os.path | |
20 | 21 | from dateutil.tz import tzlocal | |
21 | 22 | from .entry import POEntry | |
22 | 23 | ||
23 | 24 | class GettextFormat: | |
24 | 25 | 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"]) | |
26 | 31 | self.pot = polib.pofile(conf["pot"]) | |
27 | 32 | self.conf = conf | |
28 | 33 | ||
… | |||
35 | 40 | self.po.metadata['Last-Translator'] = self.conf['fullname'] | |
36 | 41 | self.po.metadata['Language'] = self.conf['lang'] | |
37 | 42 | self.po.metadata['X-Generator'] = 'Offlate ' + self.conf['version'] | |
38 | - | self.po.save() | |
43 | + | self.po.save(self.pofilename) | |
39 | 44 | ||
40 | 45 | def merge(self, older, callback): | |
41 | 46 | older.po.merge(self.pot) |