openlp/scripts/translation_utils.py

82 lines
3.2 KiB
Python
Raw Normal View History

2013-09-07 01:40:48 +00:00
#!/usr/bin/env python3
2010-04-30 22:07:51 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2020 OpenLP Developers #
2019-04-13 13:00:22 +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, either version 3 of the License, or #
# (at your option) any later version. #
# #
# 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, see <https://www.gnu.org/licenses/>. #
##########################################################################
2010-04-30 22:07:51 +00:00
"""
2019-08-18 09:15:51 +00:00
This script is used to maintain the translation files in OpenLP.
It generates the base en.ts file used to drive all translations
on Transifex.
For more details on the translation process see the Translation pages on the
Wiki
"""
2019-08-18 09:15:51 +00:00
2015-12-23 21:22:22 +00:00
import os
2010-06-09 17:09:32 +00:00
2018-10-02 04:39:42 +00:00
IGNORED_PATHS = ['scripts', 'tests']
2013-08-31 18:17:38 +00:00
IGNORED_FILES = ['setup.py']
2014-04-02 18:51: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.
"""
2019-08-18 09:15:51 +00:00
print('Generating the openlp.pro file')
lines = []
2013-08-31 18:17:38 +00:00
start_dir = os.path.abspath('..')
start_dir = start_dir + os.sep
2019-08-18 09:15:51 +00:00
print('Starting directory: %s' % start_dir)
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
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'):
if path:
2013-08-31 18:17:38 +00:00
line = '%s/%s' % (path, file)
else:
line = file
2019-08-18 09:15:51 +00:00
print('Parsing "%s"' % line)
2013-08-31 18:17:38 +00:00
lines.append('SOURCES += %s' % line)
lines.append('TRANSLATIONS += resources/i18n/en.ts')
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))
file.close()
2010-04-30 22:07:51 +00:00
2013-08-31 18:17:38 +00:00
if __name__ == '__main__':
2019-08-18 09:15:51 +00:00
prepare_project()