2013-09-07 01:40:48 +00:00
|
|
|
#!/usr/bin/env python3
|
2010-04-30 22:07:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-07-18 19:28:35 +00:00
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
2010-04-30 22:07:51 +00:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2015-01-18 13:39:21 +00:00
|
|
|
# Copyright (c) 2008-2015 OpenLP Developers #
|
2010-04-30 22:07:51 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
|
|
|
This script is used to maintain the translation files in OpenLP. It downloads
|
2012-02-05 21:18:57 +00:00
|
|
|
the latest translation files from the Transifex translation server, updates the
|
|
|
|
local translation files from both the source code and the files from Transifex,
|
2010-09-02 08:59:21 +00:00
|
|
|
and can also generate the compiled translation files.
|
|
|
|
|
|
|
|
Create New Language
|
|
|
|
-------------------
|
|
|
|
|
2012-02-05 21:18:57 +00:00
|
|
|
To create a new language, simply run this script with the ``-c`` command line
|
2010-09-02 08:59:21 +00:00
|
|
|
option::
|
|
|
|
|
2012-02-05 21:18:57 +00:00
|
|
|
@:~$ ./translation_utils.py -c
|
2010-09-02 08:59:21 +00:00
|
|
|
|
|
|
|
Update Translation Files
|
|
|
|
------------------------
|
|
|
|
|
2012-02-05 21:18:57 +00:00
|
|
|
The best way to update the translations is to download the files from Transifex,
|
2010-09-02 08:59:21 +00:00
|
|
|
and then update the local files using both the downloaded files and the source.
|
|
|
|
This is done easily via the ``-d``, ``-p`` and ``-u`` options::
|
|
|
|
|
|
|
|
@:~$ ./translation_utils.py -dpu
|
|
|
|
|
|
|
|
"""
|
2010-04-30 22:07:51 +00:00
|
|
|
import os
|
2014-04-02 18:51:21 +00:00
|
|
|
import urllib.request
|
|
|
|
import urllib.error
|
|
|
|
import urllib.parse
|
2012-02-05 20:58:17 +00:00
|
|
|
from getpass import getpass
|
|
|
|
import base64
|
|
|
|
import json
|
|
|
|
import webbrowser
|
2015-03-09 22:23:21 +00:00
|
|
|
import glob
|
2010-06-09 17:09:32 +00:00
|
|
|
|
2015-03-09 22:23:21 +00:00
|
|
|
from lxml import etree, objectify
|
2010-06-09 17:09:32 +00:00
|
|
|
from optparse import OptionParser
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtCore
|
2010-04-30 22:07:51 +00:00
|
|
|
|
2014-06-10 08:33:02 +00:00
|
|
|
SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-22x/'
|
2013-08-31 18:17:38 +00:00
|
|
|
IGNORED_PATHS = ['scripts']
|
|
|
|
IGNORED_FILES = ['setup.py']
|
2010-09-02 08:59:21 +00:00
|
|
|
|
|
|
|
verbose_mode = False
|
2010-10-10 15:40:54 +00:00
|
|
|
quiet_mode = False
|
2012-02-05 20:58:17 +00:00
|
|
|
username = ''
|
|
|
|
password = ''
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
class Command(object):
|
|
|
|
"""
|
|
|
|
Provide an enumeration of commands.
|
|
|
|
"""
|
|
|
|
Download = 1
|
|
|
|
Create = 2
|
|
|
|
Prepare = 3
|
|
|
|
Update = 4
|
|
|
|
Generate = 5
|
2015-03-09 22:23:21 +00:00
|
|
|
Check = 6
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
class CommandStack(object):
|
|
|
|
"""
|
|
|
|
This class provides an iterable stack.
|
|
|
|
"""
|
2010-06-22 17:16:39 +00:00
|
|
|
def __init__(self):
|
2010-09-02 08:59:21 +00:00
|
|
|
self.current_index = 0
|
|
|
|
self.data = []
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
return len(self.data)
|
|
|
|
|
|
|
|
def __getitem__(self, index):
|
2014-04-16 19:56:54 +00:00
|
|
|
if index not in self.data:
|
2010-09-21 19:55:40 +00:00
|
|
|
return None
|
2013-08-31 18:17:38 +00:00
|
|
|
elif self.data[index].get('arguments'):
|
|
|
|
return self.data[index]['command'], self.data[index]['arguments']
|
2010-06-22 17:16:39 +00:00
|
|
|
else:
|
2013-08-31 18:17:38 +00:00
|
|
|
return self.data[index]['command']
|
2010-09-02 08:59:21 +00:00
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
|
2013-09-07 01:40:48 +00:00
|
|
|
def __next__(self):
|
2010-09-02 08:59:21 +00:00
|
|
|
if self.current_index == len(self.data):
|
|
|
|
raise StopIteration
|
|
|
|
else:
|
2013-08-31 18:17:38 +00:00
|
|
|
current_item = self.data[self.current_index]['command']
|
2010-09-02 08:59:21 +00:00
|
|
|
self.current_index += 1
|
|
|
|
return current_item
|
|
|
|
|
|
|
|
def append(self, command, **kwargs):
|
2013-08-31 18:17:38 +00:00
|
|
|
data = {'command': command}
|
|
|
|
if 'arguments' in kwargs:
|
|
|
|
data['arguments'] = kwargs['arguments']
|
2010-09-02 08:59:21 +00:00
|
|
|
self.data.append(data)
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.current_index = 0
|
|
|
|
|
2010-09-21 19:55:40 +00:00
|
|
|
def arguments(self):
|
2013-08-31 18:17:38 +00:00
|
|
|
if self.data[self.current_index - 1].get('arguments'):
|
|
|
|
return self.data[self.current_index - 1]['arguments']
|
2010-09-21 19:55:40 +00:00
|
|
|
else:
|
|
|
|
return []
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
results = []
|
|
|
|
for item in self.data:
|
2013-08-31 18:17:38 +00:00
|
|
|
if item.get('arguments'):
|
|
|
|
results.append(str((item['command'], item['arguments'])))
|
2010-09-21 19:55:40 +00:00
|
|
|
else:
|
2013-08-31 18:17:38 +00:00
|
|
|
results.append(str((item['command'], )))
|
|
|
|
return '[%s]' % ', '.join(results)
|
2010-09-21 19:55:40 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-10-10 15:40:54 +00:00
|
|
|
def print_quiet(text, linefeed=True):
|
|
|
|
"""
|
2014-04-02 18:51:21 +00:00
|
|
|
This method checks to see if we are in quiet mode, and if not prints ``text`` out.
|
2010-10-10 15:40:54 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
:param text: The text to print.
|
|
|
|
:param linefeed: Linefeed required
|
2010-10-10 15:40:54 +00:00
|
|
|
"""
|
|
|
|
global quiet_mode
|
|
|
|
if not quiet_mode:
|
|
|
|
if linefeed:
|
2013-09-08 13:17:14 +00:00
|
|
|
print(text)
|
2010-10-10 15:40:54 +00:00
|
|
|
else:
|
2013-09-08 13:17:14 +00:00
|
|
|
print(text, end=' ')
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def print_verbose(text):
|
|
|
|
"""
|
2014-04-02 18:51:21 +00:00
|
|
|
This method checks to see if we are in verbose mode, and if so prints ``text`` out.
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
:param text: The text to print.
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
2010-10-10 15:40:54 +00:00
|
|
|
global verbose_mode, quiet_mode
|
|
|
|
if not quiet_mode and verbose_mode:
|
2013-08-31 18:17:38 +00:00
|
|
|
print(' %s' % text)
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def run(command):
|
|
|
|
"""
|
|
|
|
This method runs an external application.
|
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
:param command: The command to run.
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
|
|
|
print_verbose(command)
|
|
|
|
process = QtCore.QProcess()
|
|
|
|
process.start(command)
|
2014-04-02 18:51:21 +00:00
|
|
|
while process.waitForReadyRead():
|
2014-05-22 11:52:53 +00:00
|
|
|
print_verbose('ReadyRead: %s' % process.readAll())
|
2013-08-31 18:17:38 +00:00
|
|
|
print_verbose('Error(s):\n%s' % process.readAllStandardError())
|
|
|
|
print_verbose('Output:\n%s' % process.readAllStandardOutput())
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def download_translations():
|
|
|
|
"""
|
|
|
|
This method downloads the translation files from the Pootle server.
|
2012-02-11 18:02:33 +00:00
|
|
|
|
|
|
|
**Note:** URLs and headers need to remain strings, not unicode.
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
2012-02-05 20:58:17 +00:00
|
|
|
global username, password
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Download translation files from Transifex')
|
2012-02-05 20:58:17 +00:00
|
|
|
if not username:
|
2013-08-31 18:17:38 +00:00
|
|
|
username = input(' Transifex username: ')
|
2012-02-05 20:58:17 +00:00
|
|
|
if not password:
|
2013-08-31 18:17:38 +00:00
|
|
|
password = getpass(' Transifex password: ')
|
2012-02-05 20:58:17 +00:00
|
|
|
# First get the list of languages
|
2014-06-10 09:05:26 +00:00
|
|
|
base64string = base64.encodebytes(('%s:%s' % (username, password)).encode())[:-1]
|
|
|
|
auth_header = 'Basic %s' % base64string.decode()
|
2014-06-10 08:33:02 +00:00
|
|
|
request = urllib.request.Request(SERVER_URL + '?details')
|
2012-02-05 20:58:17 +00:00
|
|
|
request.add_header('Authorization', auth_header)
|
2014-06-10 08:33:02 +00:00
|
|
|
print_verbose('Downloading list of languages from: %s' % SERVER_URL)
|
2012-07-06 16:51:49 +00:00
|
|
|
try:
|
2013-08-31 18:17:38 +00:00
|
|
|
json_response = urllib.request.urlopen(request)
|
|
|
|
except urllib.error.HTTPError:
|
|
|
|
print_quiet('Username or password incorrect.')
|
2012-07-06 16:51:49 +00:00
|
|
|
return False
|
2014-06-10 09:05:26 +00:00
|
|
|
json_dict = json.loads(json_response.read().decode())
|
2013-08-31 18:17:38 +00:00
|
|
|
languages = [lang['code'] for lang in json_dict['available_languages']]
|
2012-02-05 20:58:17 +00:00
|
|
|
for language in languages:
|
2014-06-10 08:33:02 +00:00
|
|
|
lang_url = SERVER_URL + 'translation/%s/?file' % language
|
2013-08-31 18:17:38 +00:00
|
|
|
request = urllib.request.Request(lang_url)
|
2012-02-05 20:58:17 +00:00
|
|
|
request.add_header('Authorization', auth_header)
|
2014-04-02 18:51:21 +00:00
|
|
|
filename = os.path.join(os.path.abspath('..'), 'resources', 'i18n', language + '.ts')
|
2013-08-31 18:17:38 +00:00
|
|
|
print_verbose('Get Translation File: %s' % filename)
|
|
|
|
response = urllib.request.urlopen(request)
|
2014-06-10 09:05:26 +00:00
|
|
|
fd = open(filename, 'wb')
|
2012-02-05 20:58:17 +00:00
|
|
|
fd.write(response.read())
|
|
|
|
fd.close()
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet(' Done.')
|
2012-07-06 16:51:49 +00:00
|
|
|
return True
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def prepare_project():
|
|
|
|
"""
|
2014-04-02 18:51:21 +00:00
|
|
|
This method creates the project file needed to update the translation files and compile them into .qm files.
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Generating the openlp.pro file')
|
2010-09-02 08:59:21 +00:00
|
|
|
lines = []
|
2013-08-31 18:17:38 +00:00
|
|
|
start_dir = os.path.abspath('..')
|
2010-09-02 08:59:21 +00:00
|
|
|
start_dir = start_dir + os.sep
|
2013-08-31 18:17:38 +00:00
|
|
|
print_verbose('Starting directory: %s' % start_dir)
|
2010-09-02 08:59:21 +00:00
|
|
|
for root, dirs, files in os.walk(start_dir):
|
|
|
|
for file in files:
|
2014-04-02 18:51:21 +00:00
|
|
|
path = root.replace(start_dir, '').replace('\\', '/')
|
2013-08-31 18:17:38 +00:00
|
|
|
if file.startswith('hook-') or file.startswith('test_'):
|
2014-04-02 18:51:21 +00:00
|
|
|
continue
|
2010-09-02 08:59:21 +00:00
|
|
|
ignore = False
|
|
|
|
for ignored_path in IGNORED_PATHS:
|
|
|
|
if path.startswith(ignored_path):
|
|
|
|
ignore = True
|
|
|
|
break
|
|
|
|
if ignore:
|
|
|
|
continue
|
|
|
|
ignore = False
|
|
|
|
for ignored_file in IGNORED_FILES:
|
|
|
|
if file == ignored_file:
|
|
|
|
ignore = True
|
|
|
|
break
|
|
|
|
if ignore:
|
|
|
|
continue
|
2013-08-31 18:17:38 +00:00
|
|
|
if file.endswith('.py') or file.endswith('.pyw'):
|
2010-09-02 08:59:21 +00:00
|
|
|
if path:
|
2013-08-31 18:17:38 +00:00
|
|
|
line = '%s/%s' % (path, file)
|
2010-09-02 08:59:21 +00:00
|
|
|
else:
|
|
|
|
line = file
|
2013-08-31 18:17:38 +00:00
|
|
|
print_verbose('Parsing "%s"' % line)
|
|
|
|
lines.append('SOURCES += %s' % line)
|
|
|
|
elif file.endswith('.ts'):
|
|
|
|
line = '%s/%s' % (path, file)
|
|
|
|
print_verbose('Parsing "%s"' % line)
|
|
|
|
lines.append('TRANSLATIONS += %s' % line)
|
2010-09-02 08:59:21 +00:00
|
|
|
lines.sort()
|
2013-08-31 18:17:38 +00:00
|
|
|
file = open(os.path.join(start_dir, 'openlp.pro'), 'w')
|
2014-05-22 11:52:53 +00:00
|
|
|
file.write('\n'.join(lines))
|
2010-09-02 08:59:21 +00:00
|
|
|
file.close()
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet(' Done.')
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def update_translations():
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Update the translation files')
|
|
|
|
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
|
|
|
|
print('You have not generated a project file yet, please run this script with the -p option.')
|
2010-09-02 08:59:21 +00:00
|
|
|
return
|
|
|
|
else:
|
2013-08-31 18:17:38 +00:00
|
|
|
os.chdir(os.path.abspath('..'))
|
|
|
|
run('pylupdate4 -verbose -noobsolete openlp.pro')
|
|
|
|
os.chdir(os.path.abspath('scripts'))
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def generate_binaries():
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Generate the related *.qm files')
|
|
|
|
if not os.path.exists(os.path.join(os.path.abspath('..'), 'openlp.pro')):
|
|
|
|
print('You have not generated a project file yet, please run this script with the -p option. It is also ' +
|
2014-04-02 18:51:21 +00:00
|
|
|
'recommended that you this script with the -u option to update the translation files as well.')
|
2010-09-02 08:59:21 +00:00
|
|
|
return
|
|
|
|
else:
|
2013-08-31 18:17:38 +00:00
|
|
|
os.chdir(os.path.abspath('..'))
|
|
|
|
run('lrelease openlp.pro')
|
|
|
|
print_quiet(' Done.')
|
2010-09-21 19:22:34 +00:00
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2012-02-05 21:18:57 +00:00
|
|
|
def create_translation():
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
2012-02-05 21:18:57 +00:00
|
|
|
This method opens a browser to the OpenLP project page at Transifex so
|
|
|
|
that the user can request a new language.
|
2010-09-02 08:59:21 +00:00
|
|
|
"""
|
2014-04-02 18:51:21 +00:00
|
|
|
print_quiet('Please request a new language at the OpenLP project on Transifex.')
|
|
|
|
webbrowser.open('https://www.transifex.net/projects/p/openlp/resource/ents/')
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Opening browser to OpenLP project...')
|
2010-09-02 08:59:21 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2015-03-09 22:23:21 +00:00
|
|
|
def check_format_strings():
|
|
|
|
"""
|
|
|
|
This method runs through the ts-files and looks for mismatches between format strings in the original text
|
|
|
|
and in the translations.
|
|
|
|
"""
|
2015-03-10 23:47:17 +00:00
|
|
|
path = os.path.join(os.path.abspath('..'), 'resources', 'i18n', '*.ts')
|
2015-03-09 22:23:21 +00:00
|
|
|
file_list = glob.glob(path)
|
|
|
|
for filename in file_list:
|
|
|
|
print_quiet('Checking %s' % filename)
|
|
|
|
file = open(filename, 'rb')
|
|
|
|
tree = objectify.parse(file)
|
|
|
|
root = tree.getroot()
|
|
|
|
for tag in root.iter('message'):
|
|
|
|
location = tag.location.get('filename')
|
|
|
|
line = tag.location.get('line')
|
|
|
|
org_text = tag.source.text
|
|
|
|
translation = tag.translation.text
|
|
|
|
if not translation:
|
|
|
|
for num in tag.iter('numerusform'):
|
|
|
|
print_verbose('parsed numerusform: location: %s, source: %s, translation: %s' % (
|
2015-03-10 23:47:17 +00:00
|
|
|
location, org_text, num.text))
|
2015-03-11 08:36:24 +00:00
|
|
|
if num and org_text.count('%') != num.text.count('%'):
|
2015-03-09 22:23:21 +00:00
|
|
|
print_quiet(
|
|
|
|
'ERROR: Translation from %s at line %s has a mismatch of format input:\n%s\n%s\n' % (
|
2015-03-10 23:47:17 +00:00
|
|
|
location, line, org_text, num.text))
|
2015-03-09 22:23:21 +00:00
|
|
|
else:
|
|
|
|
print_verbose('parsed: location: %s, source: %s, translation: %s' % (location, org_text, translation))
|
|
|
|
if org_text.count('%') != translation.count('%'):
|
|
|
|
print_quiet('ERROR: Translation from %s at line %s has a mismatch of format input:\n%s\n%s\n' % (
|
2015-03-10 23:47:17 +00:00
|
|
|
location, line, org_text, translation))
|
2015-03-09 22:23:21 +00:00
|
|
|
|
|
|
|
|
2010-09-02 08:59:21 +00:00
|
|
|
def process_stack(command_stack):
|
|
|
|
"""
|
|
|
|
This method looks at the commands in the command stack, and processes them
|
|
|
|
in the order they are in the stack.
|
|
|
|
|
|
|
|
``command_stack``
|
|
|
|
The command stack to process.
|
|
|
|
"""
|
|
|
|
if command_stack:
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Processing %d commands...' % len(command_stack))
|
2010-09-02 08:59:21 +00:00
|
|
|
for command in command_stack:
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('%d.' % (command_stack.current_index), False)
|
2010-09-02 08:59:21 +00:00
|
|
|
if command == Command.Download:
|
2012-07-06 16:51:49 +00:00
|
|
|
if not download_translations():
|
|
|
|
return
|
2010-09-02 08:59:21 +00:00
|
|
|
elif command == Command.Prepare:
|
|
|
|
prepare_project()
|
|
|
|
elif command == Command.Update:
|
|
|
|
update_translations()
|
|
|
|
elif command == Command.Generate:
|
|
|
|
generate_binaries()
|
|
|
|
elif command == Command.Create:
|
2012-02-05 21:18:57 +00:00
|
|
|
create_translation()
|
2015-03-09 22:23:21 +00:00
|
|
|
elif command == Command.Check:
|
|
|
|
check_format_strings()
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('Finished processing commands.')
|
2010-09-02 08:59:21 +00:00
|
|
|
else:
|
2013-08-31 18:17:38 +00:00
|
|
|
print_quiet('No commands to process.')
|
2010-04-30 22:07:51 +00:00
|
|
|
|
2014-04-02 18:51:21 +00:00
|
|
|
|
2010-04-30 22:07:51 +00:00
|
|
|
def main():
|
2012-02-05 20:58:17 +00:00
|
|
|
global verbose_mode, quiet_mode, username, password
|
2010-04-30 22:07:51 +00:00
|
|
|
# Set up command line options.
|
2013-08-31 18:17:38 +00:00
|
|
|
usage = '%prog [options]\nOptions are parsed in the order they are ' + \
|
|
|
|
'listed below. If no options are given, "-dpug" will be used.\n\n' + \
|
|
|
|
'This script is used to manage OpenLP\'s translation files.'
|
2010-04-30 22:07:51 +00:00
|
|
|
parser = OptionParser(usage=usage)
|
2012-02-05 20:58:17 +00:00
|
|
|
parser.add_option('-U', '--username', dest='username', metavar='USERNAME',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='Transifex username, used for authentication')
|
2012-02-05 20:58:17 +00:00
|
|
|
parser.add_option('-P', '--password', dest='password', metavar='PASSWORD',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='Transifex password, used for authentication')
|
2010-09-02 08:59:21 +00:00
|
|
|
parser.add_option('-d', '--download-ts', dest='download',
|
2014-04-02 18:51:21 +00:00
|
|
|
action='store_true', help='download language files from Transifex')
|
2012-02-05 21:18:57 +00:00
|
|
|
parser.add_option('-c', '--create', dest='create', action='store_true',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='go to Transifex to request a new translation file')
|
2010-09-02 08:59:21 +00:00
|
|
|
parser.add_option('-p', '--prepare', dest='prepare', action='store_true',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='generate a project file, used to update the translations')
|
2010-06-22 17:16:39 +00:00
|
|
|
parser.add_option('-u', '--update', action='store_true', dest='update',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='update translation files (needs a project file)')
|
2010-09-02 08:59:21 +00:00
|
|
|
parser.add_option('-g', '--generate', dest='generate', action='store_true',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='compile .ts files into .qm files')
|
2010-09-02 08:59:21 +00:00
|
|
|
parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='show extra information while processing translations')
|
2010-10-10 15:40:54 +00:00
|
|
|
parser.add_option('-q', '--quiet', dest='quiet', action='store_true',
|
2014-04-02 18:51:21 +00:00
|
|
|
help='suppress all output other than errors')
|
2015-03-09 22:23:21 +00:00
|
|
|
parser.add_option('-f', '--check-format-strings', dest='check', action='store_true',
|
|
|
|
help='check that format strings are matching in translations')
|
2010-04-30 22:07:51 +00:00
|
|
|
(options, args) = parser.parse_args()
|
2010-09-02 08:59:21 +00:00
|
|
|
# Create and populate the command stack
|
|
|
|
command_stack = CommandStack()
|
2010-04-30 22:07:51 +00:00
|
|
|
if options.download:
|
2010-09-02 08:59:21 +00:00
|
|
|
command_stack.append(Command.Download)
|
2010-06-22 17:16:39 +00:00
|
|
|
if options.create:
|
2010-09-02 08:59:21 +00:00
|
|
|
command_stack.append(Command.Create, arguments=[options.create])
|
2010-06-22 17:16:39 +00:00
|
|
|
if options.prepare:
|
2010-09-02 08:59:21 +00:00
|
|
|
command_stack.append(Command.Prepare)
|
2010-06-22 17:16:39 +00:00
|
|
|
if options.update:
|
2010-09-02 08:59:21 +00:00
|
|
|
command_stack.append(Command.Update)
|
2010-06-22 17:16:39 +00:00
|
|
|
if options.generate:
|
2010-09-02 08:59:21 +00:00
|
|
|
command_stack.append(Command.Generate)
|
2015-03-09 22:23:21 +00:00
|
|
|
if options.check:
|
|
|
|
command_stack.append(Command.Check)
|
2010-09-02 08:59:21 +00:00
|
|
|
verbose_mode = options.verbose
|
2010-10-10 15:40:54 +00:00
|
|
|
quiet_mode = options.quiet
|
2012-02-05 20:58:17 +00:00
|
|
|
if options.username:
|
|
|
|
username = options.username
|
|
|
|
if options.password:
|
|
|
|
password = options.password
|
2010-09-02 08:59:21 +00:00
|
|
|
if not command_stack:
|
|
|
|
command_stack.append(Command.Download)
|
|
|
|
command_stack.append(Command.Prepare)
|
|
|
|
command_stack.append(Command.Update)
|
|
|
|
command_stack.append(Command.Generate)
|
|
|
|
# Process the commands
|
|
|
|
process_stack(command_stack)
|
2010-04-30 22:07:51 +00:00
|
|
|
|
2013-08-31 18:17:38 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
if os.path.split(os.path.abspath('.'))[1] != 'scripts':
|
|
|
|
print('You need to run this script from the scripts directory.')
|
2010-04-30 22:07:51 +00:00
|
|
|
else:
|
2010-07-27 09:32:52 +00:00
|
|
|
main()
|