mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-06-06 05:49:01 +08:00
add gen_mo.py
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# Usage
|
||||
[build_exiv2.sh](build_exiv2.sh): Used to build thirdparty library.
|
||||
[get_cache_key.py](get_cache_key.py): Used to get cache's key which used in [action/cache](https://github.com/actions/cache).
|
||||
`build_*.sh`: Used to build thirdparty library.
|
||||
[get_cache_key.py](get_cache_key.py): Used to get cache's key which used in [action/cache](https://github.com/actions/cache).
|
||||
[gen_mo.py](gen_mo.py): Used to generate .mo file. (i18n)
|
||||
|
||||
44
scripts/gen_mo.py
Normal file
44
scripts/gen_mo.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from argparse import ArgumentParser
|
||||
from os.path import abspath, dirname, exists, join
|
||||
from os import listdir, makedirs
|
||||
from sys import exit as _exit
|
||||
from traceback import print_exc
|
||||
from subprocess import Popen
|
||||
from re import compile
|
||||
|
||||
|
||||
def call(*cmd):
|
||||
print(cmd)
|
||||
p = Popen(cmd)
|
||||
p.wait()
|
||||
return p.returncode
|
||||
|
||||
|
||||
try:
|
||||
RE = compile(r'^pixiv_downloader\.(.*).po$')
|
||||
p = ArgumentParser()
|
||||
p.add_argument('-p', '--prefix', help='Translation will install at PREFIX/share/locale/<locale>/LC_MESSAGES/pixiv_downloader.mo') # noqa: E501
|
||||
p.add_argument('-o', '--output', help='Output all translations file in a directory.') # noqa: E501
|
||||
d = abspath(join(dirname(__file__), "../Language"))
|
||||
arg = p.parse_intermixed_args()
|
||||
if arg.prefix is None and arg.output is None:
|
||||
raise ValueError('--prefix or --output is needed.')
|
||||
for i in listdir(d):
|
||||
if not i.endswith('.po'):
|
||||
continue
|
||||
fn = join(d, i)
|
||||
out = None
|
||||
if arg.output:
|
||||
out = join(arg.output, i.rstrip(".po") + ".mo")
|
||||
elif arg.prefix:
|
||||
out = join(arg.prefix, 'share/locale', RE.search(i).group(1), 'LC_MESSAGES/pixiv_downloader.mo')
|
||||
if out is None:
|
||||
raise ValueError('Failed to get output file name.')
|
||||
out_dir = dirname(out)
|
||||
if not exists(out_dir):
|
||||
makedirs(out_dir, 755, exist_ok=True)
|
||||
if call('msgfmt', fn, '--output', out, '--no-hash') != 0:
|
||||
raise ValueError('Failed to run msgfmt.')
|
||||
except Exception:
|
||||
print_exc()
|
||||
_exit(1)
|
||||
Reference in New Issue
Block a user