View | Details | Raw Unified | Return to bug 41223 | Differences between
and this patch

Collapse All | Expand All

(-)a/packaging/univention-ucs-translation-template/base_makefile (+49 lines)
Line 0    Link Here 
1
#!/usr/bin/make -f
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright 2016 Univention GmbH
5
#
6
# http://www.univention.de/
7
#
8
# All rights reserved.
9
#
10
# The source code of this program is made available
11
# under the terms of the GNU Affero General Public License version 3
12
# (GNU AGPL V3) as published by the Free Software Foundation.
13
#
14
# Binary versions of this program provided by Univention to you as
15
# well as other copyrighted, protected or trademarked materials like
16
# Logos, graphics, fonts, specific documentations and configurations,
17
# cryptographic keys etc. are subject to a license agreement between
18
# you and Univention and not subject to the GNU AGPL V3.
19
#
20
# In the case you use this program under the terms of the GNU AGPL V3,
21
# the program is provided in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU Affero General Public License for more details.
25
#
26
# You should have received a copy of the GNU Affero General Public
27
# License with the Debian GNU/Linux or Univention distribution in file
28
# /usr/share/common-licenses/AGPL-3; if not, see
29
# <http://www.gnu.org/licenses/>.
30
31
# This Makefile is copied to translation source packages generated by
32
# univention-ucs-translation-build-package. It defines the receipts to build
33
# binary translation targets(mo files). The include 'all_targets.mk' is
34
# generated by the same script and contains all actual targets.
35
36
include all_targets.mk
37
38
%.mo:
39
	mkdir -p $(@D)
40
	msgfmt --check --output-file="$@" "$<"
41
42
%.json:
43
	dh-umc-po2json "$<"  # creates .json file in the same directory as the .po file
44
	mkdir -p $(@D)
45
	mv "$(patsubst %.po,%.json,$<)" "$@"
46
47
build:
48
49
install: $(ALL_TARGETS)
(-)a/packaging/univention-ucs-translation-template/debian/univention-ucs-translation-template.install (-1 / +3 lines)
 Lines 1-4    Link Here 
1
translationhelper.py usr/share/pyshared/univention
1
translationhelper.py usr/share/pyshared/univention
2
specialcases.json usr/share/univention-ucs-translation-template
2
specialcases.json usr/share/univention-ucs-translation-template
3
univention-ucs-translation-build-package.py usr/bin
3
base_makefile usr/share/univention-ucs-translation-template
4
univention-ucs-translation-merge usr/bin
5
univention-ucs-translation-build-package usr/bin
4
univention-ucs-translation-fakemessage usr/bin
6
univention-ucs-translation-fakemessage usr/bin
(-)a/packaging/univention-ucs-translation-template/translationhelper.py (-39 / +24 lines)
 Lines 44-69   MODULE_BLACKLIST = [ Link Here 
44
	'0001-6-7'
44
	'0001-6-7'
45
]
45
]
46
46
47
MAKEFILE_HEADER = """#!/usr/bin/make -f
48
49
%.mo:
50
	mkdir -p $(@D)
51
	msgfmt --check --output-file="$@" "$<"
52
53
%.json:
54
	#python -c "import univention.dh_umc as dhumc; dhumc.create_json_file('$<')"
55
	dh-umc-po2json "$<"  # creates .json file in the same directory as the .po file
56
	mkdir -p $(@D)
57
	mv "$(patsubst %.po,%.json,$<)" "$@"
58
	#install -D $($<:.po=.json) "$@"
59
60
"""
61
62
MAKEFILE_END = """build:
63
64
install: $(ALL_TARGETS)
65
"""
66
67
47
68
class UMCModuleTranslation(dh_umc.UMC_Module):
48
class UMCModuleTranslation(dh_umc.UMC_Module):
69
	def __init__(self, attrs, target_language):
49
	def __init__(self, attrs, target_language):
 Lines 96-102   class UMCModuleTranslation(dh_umc.UMC_Module): Link Here 
96
		try:
76
		try:
97
			module = UMCModuleTranslation._get_core_module_from_source_package(module_in_source_tree, target_language)
77
			module = UMCModuleTranslation._get_core_module_from_source_package(module_in_source_tree, target_language)
98
		except AttributeError as e:
78
		except AttributeError as e:
99
			print "%s core module load failed" % str(e)
79
			print("%s core module load failed" % str(e))
100
			# TODO: Module not loaded at all --> exception?
80
			# TODO: Module not loaded at all --> exception?
101
		else:
81
		else:
102
			print("Successfully loaded as core module: {}".format(module_in_source_tree.get('abs_path_to_src_pkg')))
82
			print("Successfully loaded as core module: {}".format(module_in_source_tree.get('abs_path_to_src_pkg')))
 Lines 134-140   class UMCModuleTranslation(dh_umc.UMC_Module): Link Here 
134
		attrs['relative_path_src_pkg'] = module.get('relative_path_src_pkg')
114
		attrs['relative_path_src_pkg'] = module.get('relative_path_src_pkg')
135
		return UMCModuleTranslation(attrs, target_language)
115
		return UMCModuleTranslation(attrs, target_language)
136
116
137
#TODO: actually.. (module, output_dir)
117
118
# TODO: actually.. (module, output_dir)
138
def update_package_translation_files(module, output_dir):
119
def update_package_translation_files(module, output_dir):
139
	print("Creating directories and PO files for {module_name} in translation source package".format(**module))
120
	print("Creating directories and PO files for {module_name} in translation source package".format(**module))
140
	start_dir = os.getcwd()
121
	start_dir = os.getcwd()
 Lines 154-160   def update_package_translation_files(module, output_dir): Link Here 
154
					try:
135
					try:
155
						dh_umc.create_po_file(new_po_file_abs_path, module['module_name'], src_files)
136
						dh_umc.create_po_file(new_po_file_abs_path, module['module_name'], src_files)
156
					except dh_umc.Error as exc:
137
					except dh_umc.Error as exc:
157
						print str(exc)
138
						print(str(exc))
158
139
159
			# build python po files
140
			# build python po files
160
			_create_po_files(module.python_po_files, module.python_files)
141
			_create_po_files(module.python_po_files, module.python_files)
 Lines 168-178   def update_package_translation_files(module, output_dir): Link Here 
168
			try:
149
			try:
169
				dh_umc.module_xml2po(module, po_file_full_path, lang)
150
				dh_umc.module_xml2po(module, po_file_full_path, lang)
170
			except dh_umc.Error as exc:
151
			except dh_umc.Error as exc:
171
				print str(exc)
152
				print(str(exc))
172
153
173
	except OSError as exc:
154
	except OSError as exc:
174
		print traceback.format_exc()
155
		print(traceback.format_exc())
175
		print "error in update_package_translation_files: %s" % (exc,)
156
		print("error in update_package_translation_files: %s" % (exc,))
176
	finally:
157
	finally:
177
		os.chdir(start_dir)
158
		os.chdir(start_dir)
178
	return abs_path_translated_src_pkg
159
	return abs_path_translated_src_pkg
 Lines 195-206   def write_makefile(all_modules, special_cases, new_package_dir, target_language) Link Here 
195
176
196
	for scase in special_cases:
177
	for scase in special_cases:
197
		_append_to_target_lists(scase.get('mo_destination'), '{lang}/{po_subdir}/{lang}.po'.format(lang=target_language, **scase))
178
		_append_to_target_lists(scase.get('mo_destination'), '{lang}/{po_subdir}/{lang}.po'.format(lang=target_language, **scase))
198
	with open(os.path.join(new_package_dir, 'Makefile'), 'w') as fd:
179
	with open(os.path.join(new_package_dir, 'all_targets.mk'), 'w') as fd:
199
		fd.writelines(MAKEFILE_HEADER)
180
		fd.write("# This file is auto-generated by univention-ucs-translation-build-package and should not be edited!\n\n")
200
		fd.write('ALL_TARGETS = {}\n\n'.format(' \\\n\t'.join(mo_targets_list)))
181
		fd.write('ALL_TARGETS = {}\n\n'.format(' \\\n\t'.join(mo_targets_list)))
201
		fd.write('\n'.join(target_prerequisite))
182
		fd.write('\n'.join(target_prerequisite))
202
		fd.write('\n')
183
		fd.write('\n')
203
		fd.writelines(MAKEFILE_END)
204
184
205
185
206
# special case e.g. univention-management-modules-frontend: translation files are built with a makefile
186
# special case e.g. univention-management-modules-frontend: translation files are built with a makefile
 Lines 212-218   def translate_special_case(special_case, source_dir, target_language, output_dir Link Here 
212
	# TODO: Checks whether a special case is valid should be done on special case parsing
192
	# TODO: Checks whether a special case is valid should be done on special case parsing
213
	path_src_pkg = os.path.join(source_dir, special_case.get('package_dir'))
193
	path_src_pkg = os.path.join(source_dir, special_case.get('package_dir'))
214
	if not os.path.isdir(path_src_pkg):
194
	if not os.path.isdir(path_src_pkg):
215
		# TODO: Exception 
195
		# TODO: Exception
216
		return
196
		return
217
197
218
	new_po_path = os.path.join(output_dir, special_case.get('po_subdir'))
198
	new_po_path = os.path.join(output_dir, special_case.get('po_subdir'))
 Lines 229-245   def translate_special_case(special_case, source_dir, target_language, output_dir Link Here 
229
	if not matches:
209
	if not matches:
230
		# TODO: Exception
210
		# TODO: Exception
231
		print('Error: specialcase for {} didn\'t match any files.'.format(special_case.get('package_dir')))
211
		print('Error: specialcase for {} didn\'t match any files.'.format(special_case.get('package_dir')))
212
	# FIXME: create_po should handle path itself?
213
	cwd = os.getcwd()
214
	os.chdir(path_src_pkg)
232
	try:
215
	try:
216
		matches = [os.path.relpath(match, start=os.getcwd()) for match in matches]
233
		dh_umc.create_po_file(new_po_path, special_case.get('package_name'), matches)
217
		dh_umc.create_po_file(new_po_path, special_case.get('package_name'), matches)
234
	except dh_umc.Error as exc:
218
	except dh_umc.Error as exc:
235
		repr(exc)
219
		repr(exc)
236
	except TypeError as exc:
220
	except TypeError as exc:
237
		repr(exc)
221
		repr(exc)
222
	os.chdir(cwd)
238
223
239
224
240
def find_base_translation_modules(startdir, source_dir, module_basefile_name):
225
def find_base_translation_modules(startdir, source_dir, module_basefile_name):
241
	print 'looking in %s' % source_dir
226
	print('looking in %s' % source_dir)
242
	print 'looking for files matching %s' % module_basefile_name
227
	print('looking for files matching %s' % module_basefile_name)
243
	os.chdir(source_dir)
228
	os.chdir(source_dir)
244
	matches = []
229
	matches = []
245
	for root, dirnames, filenames in os.walk('.'):
230
	for root, dirnames, filenames in os.walk('.'):
 Lines 250-267   def find_base_translation_modules(startdir, source_dir, module_basefile_name): Link Here 
250
235
251
	regex = re.compile(".*/(.*)/debian/.*%s$" % re.escape(module_basefile_name))
236
	regex = re.compile(".*/(.*)/debian/.*%s$" % re.escape(module_basefile_name))
252
	for match in matches:
237
	for match in matches:
253
		print match
238
		print(match)
254
		packagenameresult = regex.search(match)
239
		packagenameresult = regex.search(match)
255
		if packagenameresult:
240
		if packagenameresult:
256
			packagename = packagenameresult.group(1)
241
			packagename = packagenameresult.group(1)
257
242
258
			modulename = os.path.basename(match.replace(module_basefile_name, ''))
243
			modulename = os.path.basename(match.replace(module_basefile_name, ''))
259
			if modulename in MODULE_BLACKLIST:
244
			if modulename in MODULE_BLACKLIST:
260
				print "Ignoring module %s: Module is blacklisted\n" % modulename
245
				print("Ignoring module %s: Module is blacklisted\n" % modulename)
261
				continue
246
				continue
262
247
263
			package_dir = os.path.dirname(os.path.dirname(match))
248
			package_dir = os.path.dirname(os.path.dirname(match))
264
			print "Found package: %s" % package_dir
249
			print("Found package: %s" % package_dir)
265
			module = {}
250
			module = {}
266
			module['module_name'] = modulename
251
			module['module_name'] = modulename
267
			module['binary_package_name'] = packagename
252
			module['binary_package_name'] = packagename
 Lines 269-275   def find_base_translation_modules(startdir, source_dir, module_basefile_name): Link Here 
269
			module['relative_path_src_pkg'] = os.path.relpath(package_dir)
254
			module['relative_path_src_pkg'] = os.path.relpath(package_dir)
270
			base_translation_modules.append(module)
255
			base_translation_modules.append(module)
271
		else:
256
		else:
272
			print "could not obtain packagename from directory %s" % match
257
			print("could not obtain packagename from directory %s" % match)
273
258
274
	os.chdir(startdir)
259
	os.chdir(startdir)
275
	return base_translation_modules
260
	return base_translation_modules
 Lines 278-284   def find_base_translation_modules(startdir, source_dir, module_basefile_name): Link Here 
278
def create_new_package(new_package_dir, target_language, target_locale, language_name, startdir):
263
def create_new_package(new_package_dir, target_language, target_locale, language_name, startdir):
279
	new_package_dir_debian = os.path.join(new_package_dir, 'debian')
264
	new_package_dir_debian = os.path.join(new_package_dir, 'debian')
280
	if not os.path.exists(new_package_dir_debian):
265
	if not os.path.exists(new_package_dir_debian):
281
		print "creating directory: %s" % new_package_dir_debian
266
		print("creating directory: %s" % new_package_dir_debian)
282
		os.makedirs(new_package_dir_debian)
267
		os.makedirs(new_package_dir_debian)
283
268
284
	translation_package_name = "univention-ucs-translation-%s" % target_language
269
	translation_package_name = "univention-ucs-translation-%s" % target_language
 Lines 409-415   usr/share/univention-management-console/i18n/%(lang)s Link Here 
409
usr/share/locale/%(lang)s/LC_MESSAGES
394
usr/share/locale/%(lang)s/LC_MESSAGES
410
""" % language_dict)
395
""" % language_dict)
411
396
412
	### Move source files and installed .mo files to new package dir
397
	shutil.copyfile('/usr/share/univention-ucs-translation-template/base_makefile', os.path.join(new_package_dir, 'Makefile'))
398
	# Move source files and installed .mo files to new package dir
413
	if os.path.exists(os.path.join(new_package_dir, 'usr')):
399
	if os.path.exists(os.path.join(new_package_dir, 'usr')):
414
		shutil.rmtree(os.path.join(new_package_dir, 'usr'))
400
		shutil.rmtree(os.path.join(new_package_dir, 'usr'))
415
	#shutil.copytree(os.path.join(startdir, 'usr'), os.path.join(new_package_dir, 'usr'))
401
	#shutil.copytree(os.path.join(startdir, 'usr'), os.path.join(new_package_dir, 'usr'))
 Lines 419-422   usr/share/locale/%(lang)s/LC_MESSAGES Link Here 
419
		shutil.rmtree(os.path.join(new_package_dir, target_language))
405
		shutil.rmtree(os.path.join(new_package_dir, target_language))
420
	shutil.copytree(os.path.join(startdir, target_language), os.path.join(new_package_dir, target_language))
406
	shutil.copytree(os.path.join(startdir, target_language), os.path.join(new_package_dir, target_language))
421
	shutil.rmtree(os.path.join(startdir, target_language))
407
	shutil.rmtree(os.path.join(startdir, target_language))
422
(-)a/packaging/univention-ucs-translation-template/univention-ucs-translation-build-package (+93 lines)
Line 0    Link Here 
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright 2013-2014 Univention GmbH
5
#
6
# http://www.univention.de/
7
#
8
# All rights reserved.
9
#
10
# The source code of this program is made available
11
# under the terms of the GNU Affero General Public License version 3
12
# (GNU AGPL V3) as published by the Free Software Foundation.
13
#
14
# Binary versions of this program provided by Univention to you as
15
# well as other copyrighted, protected or trademarked materials like
16
# Logos, graphics, fonts, specific documentations and configurations,
17
# cryptographic keys etc. are subject to a license agreement between
18
# you and Univention and not subject to the GNU AGPL V3.
19
#
20
# In the case you use this program under the terms of the GNU AGPL V3,
21
# the program is provided in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU Affero General Public License for more details.
25
#
26
# You should have received a copy of the GNU Affero General Public
27
# License with the Debian GNU/Linux or Univention distribution in file
28
# /usr/share/common-licenses/AGPL-3; if not, see
29
# <http://www.gnu.org/licenses/>.
30
31
from optparse import OptionParser
32
33
import os
34
import json
35
import univention.dh_umc as dh_umc
36
import univention.translationhelper as tlh
37
38
39
SPECIALCASES_PATH = "/usr/share/univention-ucs-translation-template/specialcases.json"
40
41
42
if __name__ == '__main__':
43
	usage = '''%prog [options] -s source_dir -c language_code -l locale -n language_name
44
e.g.: -s /path/to/ucs-repository/ -c de -l de_DE.UTF-8:UTF-8 -n Deutsch'''
45
	parser = OptionParser(usage=usage)
46
	parser.add_option('-s', '--source', action='store', dest='source_dir', help='UCS source dir from which translation files are gathered, e.g. an UCS svn base dir')
47
	parser.add_option('-c', '--languagecode', action='store', dest='target_language', help='Target language code (e.g. de)')
48
	parser.add_option('-b', '--basefiles', action='store', dest='basefiles', default='.umc-modules', help='xml file basename (default: .umc-modules)')
49
	parser.add_option('-l', '--locale', action='store', dest='target_locale', help='Target locale (e.g. de_DE.UTF-8:UTF-8)')
50
	parser.add_option('-n', '--languagename', action='store', dest='target_name', help='Language name that is shown in the UMC (e.g. Deutsch)')
51
52
	(options, args) = parser.parse_args()
53
	help_message = 'Use --help to show additional help.'
54
55
	if not options.source_dir:
56
		parser.error('Missing argument -s. %s' % help_message)
57
58
	if not options.target_language:
59
		parser.error('Missing argument -c. %s' % help_message)
60
61
	if not options.target_locale:
62
		parser.error('Missing argument -l. %s' % help_message)
63
64
	if not options.target_name:
65
		parser.error('Missing argument -n. %s' % help_message)
66
67
	options.source_dir = os.path.abspath(options.source_dir)
68
	# find all module files and move them to a language specific directory
69
	startdir = os.getcwd()
70
	base_translation_modules = tlh.find_base_translation_modules(startdir, options.source_dir, options.basefiles)
71
	dh_umc.LANGUAGES = (options.target_language, )
72
	all_modules = list()
73
	output_dir = os.path.join(os.getcwd(), options.target_language)
74
	for module_attrs in base_translation_modules:
75
		module = tlh.UMCModuleTranslation.from_source_package(module_attrs, options.target_language)
76
		all_modules.append(module)
77
		abs_path_translated_src_pkg = tlh.update_package_translation_files(module, output_dir)
78
79
	# special cases, e.g. univention-management-console-frontend
80
	special_cases = []
81
	if os.path.exists(SPECIALCASES_PATH):
82
		with open(SPECIALCASES_PATH, 'rb') as fd:
83
			special_cases = json.load(fd)
84
	else:
85
		print("Error: Could not find file {}. Several files will not be handled.".format(SPECIALCASES_PATH))
86
87
	for s_case in special_cases:
88
		tlh.translate_special_case(s_case, options.source_dir, options.target_language, output_dir)
89
90
	# create new package
91
	new_package_dir = os.path.join(startdir, 'univention-ucs-translation-%s' % options.target_language)
92
	tlh.create_new_package(new_package_dir, options.target_language, options.target_locale, options.target_name, startdir)
93
	tlh.write_makefile(all_modules, special_cases, new_package_dir, options.target_language)
(-)a/packaging/univention-ucs-translation-template/univention-ucs-translation-build-package.py (-93 lines)
 Lines 1-93    Link Here 
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright 2013-2014 Univention GmbH
5
#
6
# http://www.univention.de/
7
#
8
# All rights reserved.
9
#
10
# The source code of this program is made available
11
# under the terms of the GNU Affero General Public License version 3
12
# (GNU AGPL V3) as published by the Free Software Foundation.
13
#
14
# Binary versions of this program provided by Univention to you as
15
# well as other copyrighted, protected or trademarked materials like
16
# Logos, graphics, fonts, specific documentations and configurations,
17
# cryptographic keys etc. are subject to a license agreement between
18
# you and Univention and not subject to the GNU AGPL V3.
19
#
20
# In the case you use this program under the terms of the GNU AGPL V3,
21
# the program is provided in the hope that it will be useful,
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
# GNU Affero General Public License for more details.
25
#
26
# You should have received a copy of the GNU Affero General Public
27
# License with the Debian GNU/Linux or Univention distribution in file
28
# /usr/share/common-licenses/AGPL-3; if not, see
29
# <http://www.gnu.org/licenses/>.
30
31
from optparse import OptionParser
32
33
import os
34
import json
35
import univention.dh_umc as dh_umc
36
import univention.translationhelper as tlh
37
38
39
SPECIALCASES_PATH = "/usr/share/univention-ucs-translation-template/specialcases.json"
40
41
42
if __name__ == '__main__':
43
	usage = '''%prog [options] -s source_dir -c language_code -l locale -n language_name
44
e.g.: -s /path/to/ucs-repository/ -c de -l de_DE.UTF-8:UTF-8 -n Deutsch'''
45
	parser = OptionParser(usage=usage)
46
	parser.add_option('-s', '--source', action='store', dest='source_dir', help='UCS source dir from which translation files are gathered, e.g. an UCS svn base dir')
47
	parser.add_option('-c', '--languagecode', action='store', dest='target_language', help='Target language code (e.g. de)')
48
	parser.add_option('-b', '--basefiles', action='store', dest='basefiles', default='.umc-modules', help='xml file basename (default: .umc-modules)')
49
	parser.add_option('-l', '--locale', action='store', dest='target_locale', help='Target locale (e.g. de_DE.UTF-8:UTF-8)')
50
	parser.add_option('-n', '--languagename', action='store', dest='target_name', help='Language name that is shown in the UMC (e.g. Deutsch)')
51
52
	(options, args) = parser.parse_args()
53
	help_message = 'Use --help to show additional help.'
54
55
	if not options.source_dir:
56
		parser.error('Missing argument -s. %s' % help_message)
57
58
	if not options.target_language:
59
		parser.error('Missing argument -c. %s' % help_message)
60
61
	if not options.target_locale:
62
		parser.error('Missing argument -l. %s' % help_message)
63
64
	if not options.target_name:
65
		parser.error('Missing argument -n. %s' % help_message)
66
67
	options.source_dir = os.path.abspath(options.source_dir)
68
	# find all module files and move them to a language specific directory
69
	startdir = os.getcwd()
70
	base_translation_modules = tlh.find_base_translation_modules(startdir, options.source_dir, options.basefiles)
71
	dh_umc.LANGUAGES = (options.target_language, )
72
	all_modules = list()
73
	output_dir = os.path.join(os.getcwd(), options.target_language)
74
	for module_attrs in base_translation_modules:
75
		module = tlh.UMCModuleTranslation.from_source_package(module_attrs, options.target_language)
76
		all_modules.append(module)
77
		abs_path_translated_src_pkg = tlh.update_package_translation_files(module, output_dir)
78
79
	# special cases, e.g. univention-management-console-frontend
80
	special_cases = []
81
	if os.path.exists(SPECIALCASES_PATH):
82
		with open(SPECIALCASES_PATH, 'rb') as fd:
83
			special_cases = json.load(fd)
84
	else:
85
		print "Error: Could not find file %s. Several files will not be handled." % SPECIALCASES_PATH
86
87
	for s_case in special_cases:
88
		tlh.translate_special_case(s_case, options.source_dir, options.target_language, output_dir)
89
90
	# create new package
91
	new_package_dir = os.path.join(startdir, 'univention-ucs-translation-%s' % options.target_language)
92
	tlh.create_new_package(new_package_dir, options.target_language, options.target_locale, options.target_name, startdir)
93
	tlh.write_makefile(all_modules, special_cases, new_package_dir, options.target_language)
(-)a/packaging/univention-ucs-translation-template/univention-ucs-translation-fakemessage (-3 / +4 lines)
 Lines 37-51   USAGE = """ Link Here 
37
Usage: univention-ucs-translation-fakemessage [directory]
37
Usage: univention-ucs-translation-fakemessage [directory]
38
38
39
This script walks over all po files in a given directory and its subfolders.
39
This script walks over all po files in a given directory and its subfolders.
40
It fills all msgid strings to the corresponding msgid and prepeding it with a
40
It fills all msgid strings with the same content as the corresponding msgid,
41
character sequence '!TR!'.
41
prepeding it with the character sequence '!TR!'.
42
It is useful for visual quick testing of translation coverage and po file
42
It is useful for visual quick testing of translation coverage and po file
43
generation.
43
generation.
44
"""
44
"""
45
45
46
46
def main(po_dir):
47
def main(po_dir):
47
	for _dir, dns, fns in os.walk(os.path.abspath(po_dir)):
48
	for _dir, dns, fns in os.walk(os.path.abspath(po_dir)):
48
		for po_file in fnmatch.filter(fns, '*po'):
49
		for po_file in fnmatch.filter(fns, '*.po'):
49
			po = polib.pofile(os.path.join(_dir, po_file))
50
			po = polib.pofile(os.path.join(_dir, po_file))
50
			for entry in po:
51
			for entry in po:
51
				if entry.msgid == '':
52
				if entry.msgid == '':
(-)a/packaging/univention-ucs-translation-template/univention-ucs-translation-merge (-11 / +37 lines)
 Lines 29-40    Link Here 
29
# <http://www.gnu.org/licenses/>.
29
# <http://www.gnu.org/licenses/>.
30
import argparse
30
import argparse
31
import fnmatch
31
import fnmatch
32
import polib
33
import os
32
import os
34
import sys
33
import sys
34
import shutil
35
import univention.translationhelper as tlh
35
import univention.translationhelper as tlh
36
import univention.dh_umc as dh_umc
36
import univention.dh_umc as dh_umc
37
import json
37
import json
38
import subprocess
39
from pdb import set_trace as dbg
38
40
39
SPECIALCASES_PATH = "/usr/share/univention-ucs-translation-template/specialcases.json"
41
SPECIALCASES_PATH = "/usr/share/univention-ucs-translation-template/specialcases.json"
40
42
 Lines 50-55   def _get_po_files_from_dir(directory, return_relative_path=False): Link Here 
50
	return po_files
52
	return po_files
51
53
52
54
55
def _msgmerge(source, destination):
56
	try:
57
		subprocess.check_call(['msgmerge', '--update', '--sort-output', destination, source])
58
	except TypeError:
59
		print('Error: arguments must be names of existing files. Exiting.')
60
		sys.exit(1)
61
	except subprocess.CalledProcessError:
62
		print('Error: PO file merge failed. Exiting.')
63
		sys.exit(1)
64
65
53
def merge_po_file_trees(source_tree, target_tree):
66
def merge_po_file_trees(source_tree, target_tree):
54
	upstream_pos = _get_po_files_from_dir(source_tree, return_relative_path=True)
67
	upstream_pos = _get_po_files_from_dir(source_tree, return_relative_path=True)
55
	translated_pos = _get_po_files_from_dir(target_tree, return_relative_path=True)
68
	translated_pos = _get_po_files_from_dir(target_tree, return_relative_path=True)
 Lines 62-77   def merge_po_file_trees(source_tree, target_tree): Link Here 
62
	# add new
75
	# add new
63
	for new_po in new_pos:
76
	for new_po in new_pos:
64
		new_po_path = os.path.join(target_tree, new_po)
77
		new_po_path = os.path.join(target_tree, new_po)
65
		os.makedirs(os.path.dirname(new_po_path))
78
		try:
79
			os.makedirs(os.path.dirname(new_po_path))
80
		except OSError as exc:
81
			if not exc.errno == 17:
82
				raise
83
			pass
66
		os.rename(os.path.join(source_tree, new_po), new_po_path)
84
		os.rename(os.path.join(source_tree, new_po), new_po_path)
85
		upstream_pos.remove(new_po)
67
	# merge upstream changes...
86
	# merge upstream changes...
68
	for dir, dirs, files in os.walk(target_tree):
87
	for po_file in upstream_pos:
69
		for po_file in fnmatch.filter([os.path.join(dir, fn) for fn in files], '*.po'):
88
		_msgmerge(os.path.join(source_tree, po_file), os.path.join(target_tree, po_file))
70
			translated = polib.pofile(po_file)
89
	return pos_delete_upstream, new_pos
71
			upstream = polib.pofile(po_file.replace(target_tree, source_tree))
72
			translated.merge(upstream)
73
			translated.save()
74
75
90
76
if __name__ == '__main__':
91
if __name__ == '__main__':
77
	parser = argparse.ArgumentParser(description="Merge upstream changes in translation files to existing translation source package.")
92
	parser = argparse.ArgumentParser(description="Merge upstream changes in translation files to existing translation source package.")
 Lines 91-98   if __name__ == '__main__': Link Here 
91
	dh_umc.LANGUAGES = (args.lang_code, )
106
	dh_umc.LANGUAGES = (args.lang_code, )
92
	modules_upstream = tlh.find_base_translation_modules(os.getcwd(), args.upstream, '.umc-modules')
107
	modules_upstream = tlh.find_base_translation_modules(os.getcwd(), args.upstream, '.umc-modules')
93
	output_dir = os.path.join(args.translation, '{}_merge'.format(args.lang_code))
108
	output_dir = os.path.join(args.translation, '{}_merge'.format(args.lang_code))
109
	modules = list()
94
	for module_attrs in modules_upstream:
110
	for module_attrs in modules_upstream:
95
		module = tlh.UMCModuleTranslation.from_source_package(module_attrs, args.lang_code)
111
		module = tlh.UMCModuleTranslation.from_source_package(module_attrs, args.lang_code)
112
		modules.append(module)
96
		tlh.update_package_translation_files(module, output_dir)
113
		tlh.update_package_translation_files(module, output_dir)
97
	# special cases, e.g. univention-management-console-frontend
114
	# special cases, e.g. univention-management-console-frontend
98
	special_cases = []
115
	special_cases = []
 Lines 100-108   if __name__ == '__main__': Link Here 
100
		with open(SPECIALCASES_PATH, 'rb') as fd:
117
		with open(SPECIALCASES_PATH, 'rb') as fd:
101
			special_cases = json.load(fd)
118
			special_cases = json.load(fd)
102
	else:
119
	else:
103
		print "Error: Could not find file %s. Several files will not be handled." % SPECIALCASES_PATH
120
		print("Error: Could not find file {}.\nSeveral files will not be handled.".format(SPECIALCASES_PATH))
104
121
105
	for scase in special_cases:
122
	for scase in special_cases:
106
		tlh.translate_special_case(scase, args.upstream, args.lang_code, output_dir)
123
		tlh.translate_special_case(scase, args.upstream, args.lang_code, output_dir)
107
124
108
	merge_po_file_trees(output_dir, os.path.join(args.translation, args.lang_code))
125
	removed, new = merge_po_file_trees(output_dir, os.path.join(args.translation, args.lang_code))
126
	print('Merge summary: ')
127
	if removed:
128
		print('Following files have been removed:')
129
		print('\n'.join(removed))
130
	if new:
131
		print('Following files habe been added:')
132
		print('\n'.join(new))
133
	shutil.rmtree(output_dir)
134
	tlh.write_makefile(modules, special_cases, args.translation, args.lang_code)

Return to bug 41223