Home | Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 4 # Copyright 2008 Zuza Software Foundation 5 # 6 # This file is part of the Translate Toolkit. 7 # 8 # This program is free software; you can redistribute it and/or modify 9 # it under the terms of the GNU General Public License as published by 10 # the Free Software Foundation; either version 2 of the License, or 11 # (at your option) any later version. 12 # 13 # This program is distributed in the hope that it will be useful, 14 # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 # GNU General Public License for more details. 17 # 18 # You should have received a copy of the GNU General Public License 19 # along with this program; if not, see <http://www.gnu.org/licenses/>. 20 21 """convert Gettext PO localization files to Symbian translation files.""" 22 23 from translate.storage import factory 24 from translate.storage.pypo import po_escape_map 25 from translate.storage.symbian import * 26 2729 for key, val in po_escape_map.iteritems(): 30 text = text.replace(key, val) 31 return '"%s"' % text32 3335 match = read_while(ps, header_item_or_end_re.match, lambda match: match is None) 36 while not ps.current_line.startswith('*/'): 37 match = header_item_re.match(ps.current_line) 38 if match is not None: 39 key = match.groupdict()['key'] 40 if key in replacments: 41 ps.current_line = match.expand('\g<key>\g<space>%s\n' % replacments[key]) 42 ps.read_line()43 4446 replace_header_items(ps, header_replacements) 47 try: 48 while True: 49 eat_whitespace(ps) 50 skip_no_translate(ps) 51 match = string_entry_re.match(ps.current_line) 52 if match is not None: 53 key = match.groupdict()['id'] 54 if key in body_replacements: 55 value = body_replacements[key].target or body_replacements[key].source 56 ps.current_line = match.expand(u'\g<start>\g<id>\g<space>%s\n' % escape(value)) 57 ps.read_line() 58 except StopIteration: 59 pass60 61 67 return result, save_line 68 6971 lines = list(f) 72 charset = read_charset(lines) 73 result, save_line = line_saver(charset) 74 parse(ParseState(iter(lines), charset, save_line), header_replacements, body_replacements) 75 return result76 7779 po_header = store.parseheader() 80 index = {} 81 for unit in store.units: 82 for location in unit.getlocations(): 83 index[location] = unit 84 index['r_string_languagegroup_name'] = store.UnitClass(po_header['Language-Team']) 85 return index86 87 91 9293 -def convert_symbian(input_file, output_file, template_file, pot=False, duplicatestyle="msgctxt"):94 store = factory.getobject(input_file) 95 location_index = build_location_index(store) 96 header_index = build_header_index(store) 97 output = write_symbian(template_file, header_index, location_index) 98 for line in output: 99 output_file.write(line) 100 return 1101 102104 from translate.convert import convert 105 formats = {"po": ("r0", convert_symbian)} 106 parser = convert.ConvertOptionParser(formats, usetemplates=True, usepots=True, description=__doc__) 107 parser.add_duplicates_option() 108 parser.passthrough.append("pot") 109 parser.run(argv)110 111 112 if __name__ == '__main__': 113 main() 114
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jan 19 17:50:29 2011 | http://epydoc.sourceforge.net |