Commit e4a922c4 authored by Tankypon's avatar Tankypon

Create the python file to generate .pot, .po and .mo files

parent 169070d7
......@@ -10,20 +10,19 @@ Description :
Just watch your favorite show and keep track of them.
"""
import gettext
import sys
from argparse import ArgumentParser
from bottle import *
from threading import Thread
from urllib.parse import quote as quoteurl
import gettext
from utils import *
from webutils import *
from database import DontPanicDB
from subtitles import get_hash, sch_subtitle, dl_subtitle
from torrentsession import TorrentSession
from database import DontPanicDB
from utils import *
from webutils import *
gettext.bindtextdomain('dontpanic', '/usr/share/locale')
gettext.textdomain('dontpanic')
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gettext
import logging
import os
import subprocess
from argparse import ArgumentParser
from glob import glob
from utils import progname, localedir, podir, setup_logging
i18n_domain = gettext.textdomain()
_ = gettext.gettext
logger = logging.getLogger(__name__)
def update_pot():
if not os.path.exists(podir):
os.makedirs(podir)
cmd = ['xgettext', '--language=Python', '--package-name', i18n_domain,
'--output', '{}/{}.pot'.format(podir, i18n_domain)]
for path, names, filenames in os.walk(os.curdir):
for f in filenames:
if f.endswith('.py'):
cmd.append(os.path.join(path, f))
subprocess.call(cmd)
def update_po():
source_pot = os.path.join(podir, '{}.pot'.format(i18n_domain))
for po_file in glob(os.path.join(podir, '*.po')):
subprocess.check_call(["msgmerge", "--update", po_file, source_pot])
def update_mo():
for filename in os.listdir(podir):
if not filename.endswith('.po'):
continue
lang = filename[:-3]
src = os.path.join(podir, filename)
dest_path = os.path.join(localedir, lang, 'LC_MESSAGES')
dest = os.path.join(dest_path, i18n_domain + '.mo')
if not os.path.exists(dest_path):
os.makedirs(dest_path)
if not os.path.exists(dest):
logger.info('Compiling {}'.format(src))
subprocess.call(["msgfmt", src, "--output-file", dest])
else:
src_mtime = os.stat(src)[8]
dest_mtime = os.stat(dest)[8]
if src_mtime > dest_mtime:
logger.info('Compiling {}'.format(src))
subprocess.call(["msgfmt", src, "--output-file", dest])
if __name__ == "__main__":
parser = ArgumentParser(prog=progname, description=_("Update translation for Dontpanic."))
parser.add_argument("-v", "--verbose", action="count", default=0, help=_("Increase output verbosity"))
parser.add_argument("-pot", "--update_pot", action="store_true", help=_("Update template for translators"))
parser.add_argument("-po", "--update_po", action="store_true", help=_("Update po from pot file"))
parser.add_argument("-mo", "--update_mo", action="store_true", help=_("Compile .po files into .mo files"))
args = parser.parse_args()
setup_logging(args.verbose)
if args.update_pot:
update_pot()
if args.update_po:
update_po()
if args.update_mo:
update_mo()
\ No newline at end of file
......@@ -15,6 +15,8 @@ gettext.bindtextdomain('dontpanic', '/usr/share/locale')
gettext.textdomain('dontpanic')
_ = gettext.gettext
podir = os.path.join(os.path.dirname(os.curdir), 'po')
localedir = os.path.join(os.path.dirname(os.curdir), 'locale')
confdir = os.path.expanduser('~/.dontpanic')
tempdir = tempfile.mkdtemp(prefix="dontpanic")
watchlist_file = os.path.join(confdir, 'watchlist.pkl')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment