Port the building of translations

This commit is contained in:
Kovid Goyal 2014-05-26 12:01:03 +05:30
parent 6ae2fcc7a6
commit 53a7d0f330

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, tempfile, shutil, subprocess, glob, re, time, textwrap, cPickle import os, tempfile, shutil, subprocess, glob, re, time, textwrap, cPickle, shlex
from locale import normalize as normalize_locale from locale import normalize as normalize_locale
from functools import partial from functools import partial
@ -25,8 +25,14 @@ class POT(Command): # {{{
description = 'Update the .pot translation template and upload it' description = 'Update the .pot translation template and upload it'
TRANSLATIONS = os.path.join(os.path.dirname(Command.SRC), 'translations') TRANSLATIONS = os.path.join(os.path.dirname(Command.SRC), 'translations')
def tx(self, cmd, **kw):
kw['cwd'] = kw.get('cwd', self.TRANSLATIONS)
if hasattr(cmd, 'format'):
cmd = shlex.split(cmd)
return subprocess.check_call(['tx'] + cmd, **kw)
def upload_pot(self, pot): def upload_pot(self, pot):
return # TODO: Implement this self.tx('push -r calibre.main -s', cwd=self.TRANSLATIONS)
def source_files(self): def source_files(self):
ans = [] ans = []
@ -69,7 +75,7 @@ class POT(Command): # {{{
return '\n'.join(ans) return '\n'.join(ans)
def run(self, opts): def run(self, opts):
# require_git_master() TODO: Re-enable this once migration is done require_git_master()
pot_header = textwrap.dedent('''\ pot_header = textwrap.dedent('''\
# Translation template file.. # Translation template file..
# Copyright (C) %(year)s Kovid Goyal # Copyright (C) %(year)s Kovid Goyal
@ -139,7 +145,7 @@ class Translations(POT): # {{{
'locales') 'locales')
def po_files(self): def po_files(self):
return glob.glob(os.path.join(self.LP_PATH, '*.po')) return glob.glob(os.path.join(self.TRANSLATIONS, __appname__, '*.po'))
def mo_file(self, po_file): def mo_file(self, po_file):
locale = os.path.splitext(os.path.basename(po_file))[0] locale = os.path.splitext(os.path.basename(po_file))[0]
@ -159,7 +165,7 @@ class Translations(POT): # {{{
self.info('\tCompiling translations for', locale) self.info('\tCompiling translations for', locale)
subprocess.check_call(['msgfmt', '-o', dest, f]) subprocess.check_call(['msgfmt', '-o', dest, f])
iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale) iscpo = {'bn':'bn_IN', 'zh_HK':'zh_CN'}.get(locale, locale)
iso639 = self.j(self.LP_ISO_PATH, '%s.po'%iscpo) iso639 = self.j(self.TRANSLATIONS, 'iso_639', '%s.po'%iscpo)
if os.path.exists(iso639): if os.path.exists(iso639):
self.check_iso639(iso639) self.check_iso639(iso639)
@ -170,7 +176,7 @@ class Translations(POT): # {{{
elif locale not in { elif locale not in {
'en_GB', 'en_CA', 'en_AU', 'si', 'ur', 'sc', 'ltg', 'nds', 'en_GB', 'en_CA', 'en_AU', 'si', 'ur', 'sc', 'ltg', 'nds',
'te', 'yi', 'fo', 'sq', 'ast', 'ml', 'ku', 'fr_CA', 'him', 'te', 'yi', 'fo', 'sq', 'ast', 'ml', 'ku', 'fr_CA', 'him',
'jv', 'ka', 'fur', 'ber', 'my', 'fil', 'hy'}: 'jv', 'ka', 'fur', 'ber', 'my', 'fil', 'hy', 'ug'}:
self.warn('No ISO 639 translations for locale:', locale) self.warn('No ISO 639 translations for locale:', locale)
ln = normalize_locale(locale).partition('.')[0] ln = normalize_locale(locale).partition('.')[0]
@ -234,7 +240,7 @@ class Translations(POT): # {{{
if not self.newer(dest, files): if not self.newer(dest, files):
return return
self.info('Calculating translation statistics...') self.info('Calculating translation statistics...')
raw = self.get_stats(self.j(self.LP_PATH, 'calibre.pot')) raw = self.get_stats(self.j(self.TRANSLATIONS, __appname__, 'main.pot'))
total = int(raw.split(',')[-1].strip().split()[0]) total = int(raw.split(',')[-1].strip().split()[0])
stats = {} stats = {}
for f in files: for f in files:
@ -257,8 +263,7 @@ class Translations(POT): # {{{
class GetTranslations(Translations): # {{{ class GetTranslations(Translations): # {{{
description = 'Get updated translations from Launchpad' description = 'Get updated translations from Transifex'
BRANCH = 'lp:~kovid/calibre/translations'
CMSG = 'Updated translations' CMSG = 'Updated translations'
@property @property