]> git.lyx.org Git - lyx.git/blob - po/lyx_pot.py
Add icon library to link target - needed on Mac OS X - thanks Kornel
[lyx.git] / po / lyx_pot.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # file lyx_pot.py
5 # This file is part of LyX, the document processor.
6 # Licence details can be found in the file COPYING.
7 #
8 # \author Bo Peng
9 #
10 # Full author contact details are available in file CREDITS
11
12 # Usage: use
13 #     lyx_pot.py -h
14 # to get usage message
15
16 # This script will extract translatable strings from input files and write
17 # to output in gettext .pot format.
18 #
19 import sys, os, re, getopt
20 if sys.version_info < (2, 4, 0):
21     from sets import Set as set
22
23 def relativePath(path, base):
24     '''return relative path from top source dir'''
25     # full pathname of path
26     path1 = os.path.normpath(os.path.realpath(path)).split(os.sep)
27     path2 = os.path.normpath(os.path.realpath(base)).split(os.sep)
28     if path1[:len(path2)] != path2:
29         print "Path %s is not under top source directory" % path
30     path3 = os.path.join(*path1[len(path2):]);
31     # replace all \ by / such that we get the same comments on Windows and *nix
32     path3 = path3.replace('\\', '/')
33     return path3
34
35
36 def writeString(outfile, infile, basefile, lineno, string):
37     string = string.replace('\\', '\\\\').replace('"', '')
38     if string == "":
39         return
40     print >> outfile, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
41         (relativePath(infile, basefile), lineno, string)
42
43
44 def ui_l10n(input_files, output, base):
45     '''Generate pot file from lib/ui/*'''
46     output = open(output, 'w')
47     Submenu = re.compile(r'^[^#]*Submenu\s+"([^"]*)"', re.IGNORECASE)
48     Popupmenu = re.compile(r'^[^#]*PopupMenu\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE)
49     IconPalette = re.compile(r'^[^#]*IconPalette\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE)
50     Toolbar = re.compile(r'^[^#]*Toolbar\s+"[^"]+"\s+"([^"]*)"', re.IGNORECASE)
51     Item = re.compile(r'[^#]*Item\s+"([^"]*)"', re.IGNORECASE)
52     TableInsert = re.compile(r'[^#]*TableInsert\s+"([^"]*)"', re.IGNORECASE)
53     for src in input_files:
54         input = open(src)
55         for lineno, line in enumerate(input.readlines()):
56             if Submenu.match(line):
57                 (string,) = Submenu.match(line).groups()
58                 string = string.replace('_', ' ')
59             elif Popupmenu.match(line):
60                 (string,) = Popupmenu.match(line).groups()
61             elif IconPalette.match(line):
62                 (string,) = IconPalette.match(line).groups()
63             elif Toolbar.match(line):
64                 (string,) = Toolbar.match(line).groups()
65             elif Item.match(line):
66                 (string,) = Item.match(line).groups()
67             elif TableInsert.match(line):
68                 (string,) = TableInsert.match(line).groups()
69             else:
70                 continue
71             string = string.replace('"', '')
72             if string != "":
73                 print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
74                     (relativePath(src, base), lineno+1, string)
75         input.close()
76     output.close()
77
78
79 def layouts_l10n(input_files, output, base, layouttranslations):
80     '''Generate pot file from lib/layouts/*.{layout,inc,module}'''
81     ClassDescription = re.compile(r'^\s*#\s*\\Declare(LaTeX|DocBook)Class.*\{(.*)\}$', re.IGNORECASE)
82     ClassCategory = re.compile(r'^\s*#\s*\\DeclareCategory\{(.*)\}$', re.IGNORECASE)
83     Style = re.compile(r'^\s*Style\s+(.*\S)\s*$', re.IGNORECASE)
84     # match LabelString, EndLabelString, LabelStringAppendix and maybe others but no comments
85     LabelString = re.compile(r'^[^#]*LabelString\S*\s+(.*\S)\s*$', re.IGNORECASE)
86     MenuString = re.compile(r'^[^#]*MenuString\S*\s+(.*\S)\s*$', re.IGNORECASE)
87     Tooltip = re.compile(r'^\s*Tooltip\S*\s+(.*\S)\s*$', re.IGNORECASE)
88     GuiName = re.compile(r'^\s*GuiName\s+(.*\S)\s*$', re.IGNORECASE)
89     ListName = re.compile(r'^\s*ListName\s+(.*\S)\s*$', re.IGNORECASE)
90     CategoryName = re.compile(r'^\s*Category\s+(.*\S)\s*$', re.IGNORECASE)
91     NameRE = re.compile(r'^\s*#\s*\\DeclareLyXModule.*{(.*)}$', re.IGNORECASE)
92     InsetLayout = re.compile(r'^InsetLayout\s+\"?(.*)\"?\s*$', re.IGNORECASE)
93     FlexCheck = re.compile(r'^Flex:(.*)', re.IGNORECASE)
94     CaptionCheck = re.compile(r'^Caption:(.*)', re.IGNORECASE)
95     DescBegin = re.compile(r'^\s*#DescriptionBegin\s*$', re.IGNORECASE)
96     DescEnd = re.compile(r'^\s*#\s*DescriptionEnd\s*$', re.IGNORECASE)
97     Category = re.compile(r'^\s*#\s*Category:\s+(.*\S)\s*$', re.IGNORECASE)
98     I18nPreamble = re.compile(r'^\s*((Lang)|(Babel))Preamble\s*$', re.IGNORECASE)
99     EndI18nPreamble = re.compile(r'^\s*End((Lang)|(Babel))Preamble\s*$', re.IGNORECASE)
100     I18nString = re.compile(r'_\(([^\)]+)\)')
101     CounterFormat = re.compile(r'^\s*PrettyFormat\s+"?(.*)"?\s*$', re.IGNORECASE)
102     CiteFormat = re.compile(r'^\s*CiteFormat', re.IGNORECASE)
103     KeyVal = re.compile(r'^\s*_\w+\s+(.*\S)\s*$')
104     Float = re.compile(r'^\s*Float\s*$', re.IGNORECASE)
105     UsesFloatPkg = re.compile(r'^\s*UsesFloatPkg\s+(.*\S)\s*$', re.IGNORECASE)
106     IsPredefined = re.compile(r'^\s*IsPredefined\s+(.*\S)\s*$', re.IGNORECASE)
107     End = re.compile(r'^\s*End', re.IGNORECASE)
108     Comment = re.compile(r'^(.*)#')
109     Translation = re.compile(r'^\s*Translation\s+(.*\S)\s*$', re.IGNORECASE)
110     KeyValPair = re.compile(r'\s*"(.*)"\s+"(.*)"')
111
112     oldlanguages = []
113     languages = []
114     keyset = set()
115     oldtrans = dict()
116     if layouttranslations:
117         linguas_file = os.path.join(base, 'po/LINGUAS')
118         for line in open(linguas_file).readlines():
119             res = Comment.search(line)
120             if res:
121                 line = res.group(1)
122             if line.strip() != '':
123                 languages.extend(line.split())
124
125         # read old translations if available
126         try:
127             input = open(output)
128             lang = ''
129             for line in input.readlines():
130                 res = Comment.search(line)
131                 if res:
132                     line = res.group(1)
133                 if line.strip() == '':
134                     continue
135                 res = Translation.search(line)
136                 if res:
137                     lang = res.group(1)
138                     if lang not in languages:
139                         oldlanguages.append(lang)
140                         languages.append(lang)
141                     oldtrans[lang] = dict()
142                     continue
143                 res = End.search(line)
144                 if res:
145                     lang = ''
146                     continue
147                 res = KeyValPair.search(line)
148                 if res and lang != '':
149                     key = res.group(1).decode('utf-8')
150                     val = res.group(2).decode('utf-8')
151                     key = key.replace('\\"', '"').replace('\\\\', '\\')
152                     val = val.replace('\\"', '"').replace('\\\\', '\\')
153                     oldtrans[lang][key] = val
154                     keyset.add(key)
155                     continue
156                 print "Error: Unable to handle line:"
157                 print line
158         except IOError:
159             print "Warning: Unable to open %s for reading." % output
160             print "         Old translations will be lost."
161
162         # walon is not a known document language
163         # FIXME: Do not hardcode, read from lib/languages!
164         if 'wa' in languages:
165             languages.remove('wa')
166
167     out = open(output, 'w')
168     for src in input_files:
169         readingDescription = False
170         readingI18nPreamble = False
171         readingFloat = False
172         readingCiteFormats = False
173         isPredefined = False
174         usesFloatPkg = True
175         listname = ''
176         floatname = ''
177         descStartLine = -1
178         descLines = []
179         lineno = 0
180         for line in open(src).readlines():
181             lineno += 1
182             res = ClassDescription.search(line)
183             if res != None:
184                 string = res.group(2)
185                 if not layouttranslations:
186                     writeString(out, src, base, lineno + 1, string)
187                 continue
188             res = ClassCategory.search(line)
189             if res != None:
190                 string = res.group(1)
191                 if not layouttranslations:
192                     writeString(out, src, base, lineno + 1, string)
193                 continue
194             if readingDescription:
195                 res = DescEnd.search(line)
196                 if res != None:
197                     readingDescription = False
198                     desc = " ".join(descLines)
199                     if not layouttranslations:
200                         writeString(out, src, base, lineno + 1, desc)
201                     continue
202                 descLines.append(line[1:].strip())
203                 continue
204             res = DescBegin.search(line)
205             if res != None:
206                 readingDescription = True
207                 descStartLine = lineno
208                 continue
209             if readingI18nPreamble:
210                 res = EndI18nPreamble.search(line)
211                 if res != None:
212                     readingI18nPreamble = False
213                     continue
214                 res = I18nString.search(line)
215                 if res != None:
216                     string = res.group(1)
217                     if layouttranslations:
218                         keyset.add(string)
219                     else:
220                         writeString(out, src, base, lineno, string)
221                 continue
222             res = I18nPreamble.search(line)
223             if res != None:
224                 readingI18nPreamble = True
225                 continue
226             res = NameRE.search(line)
227             if res != None:
228                 string = res.group(1)
229                 if not layouttranslations:
230                     writeString(out, src, base, lineno + 1, string)
231                 continue
232             res = Style.search(line)
233             if res != None:
234                 string = res.group(1)
235                 string = string.replace('_', ' ')
236                 # Style means something else inside a float definition
237                 if not readingFloat:
238                     if not layouttranslations:
239                         writeString(out, src, base, lineno, string)
240                 continue
241             res = LabelString.search(line)
242             if res != None:
243                 string = res.group(1)
244                 if not layouttranslations:
245                     writeString(out, src, base, lineno, string)
246                 continue
247             res = MenuString.search(line)
248             if res != None:
249                 string = res.group(1)
250                 if not layouttranslations:
251                     writeString(out, src, base, lineno, string)
252                 continue
253             res = Tooltip.search(line)
254             if res != None:
255                 string = res.group(1)
256                 if not layouttranslations:
257                     writeString(out, src, base, lineno, string)
258                 continue
259             res = GuiName.search(line)
260             if res != None:
261                 string = res.group(1)
262                 if layouttranslations:
263                     # gui name must only be added for floats
264                     if readingFloat:
265                         floatname = string
266                 else:
267                     writeString(out, src, base, lineno, string)
268                 continue
269             res = CategoryName.search(line)
270             if res != None:
271                 string = res.group(1)
272                 if not layouttranslations:
273                     writeString(out, src, base, lineno, string)
274                 continue
275             res = ListName.search(line)
276             if res != None:
277                 string = res.group(1)
278                 if layouttranslations:
279                     listname = string.strip('"')
280                 else:
281                     writeString(out, src, base, lineno, string)
282                 continue
283             res = InsetLayout.search(line)
284             if res != None:
285                 string = res.group(1)
286                 string = string.replace('_', ' ')
287                 #Flex:xxx is not used in translation
288                 #if not layouttranslations:
289                 #    writeString(out, src, base, lineno, string)
290                 m = FlexCheck.search(string)
291                 if m:
292                     if not layouttranslations:
293                         writeString(out, src, base, lineno, m.group(1))
294                 m = CaptionCheck.search(string)
295                 if m:
296                     if not layouttranslations:
297                         writeString(out, src, base, lineno, m.group(1))
298                 continue
299             res = Category.search(line)
300             if res != None:
301                 string = res.group(1)
302                 if not layouttranslations:
303                     writeString(out, src, base, lineno, string)
304                 continue
305             res = CounterFormat.search(line)
306             if res != None:
307                 string = res.group(1)
308                 if not layouttranslations:
309                     writeString(out, src, base, lineno, string)
310                 continue
311             res = Float.search(line)
312             if res != None:
313                 readingFloat = True
314                 continue
315             res = IsPredefined.search(line)
316             if res != None:
317                 string = res.group(1).lower()
318                 if string == 'true':
319                     isPredefined = True
320                 else:
321                     isPredefined = False
322                 continue
323             res = UsesFloatPkg.search(line)
324             if res != None:
325                 string = res.group(1).lower()
326                 if string == 'true':
327                     usesFloatPkg = True
328                 else:
329                     usesFloatPkg = False
330                 continue
331             res = CiteFormat.search(line)
332             if res != None:
333                 readingCiteFormats = True
334                 continue
335             res = End.search(line)
336             if res != None:
337                 # We have four combinations of the flags usesFloatPkg and isPredefined:
338                 #     usesFloatPkg and     isPredefined: might use standard babel translations
339                 #     usesFloatPkg and not isPredefined: does not use standard babel translations
340                 # not usesFloatPkg and     isPredefined: uses standard babel translations
341                 # not usesFloatPkg and not isPredefined: not supported by LyX
342                 # The third combination is even true for MarginFigure, MarginTable (both from
343                 # tufte-book.layout) and Planotable, Plate (both from aguplus.inc).
344                 if layouttranslations and readingFloat and usesFloatPkg:
345                     if floatname != '':
346                         keyset.add(floatname)
347                     if listname != '':
348                         keyset.add(listname)
349                 isPredefined = False
350                 usesFloatPkg = True
351                 listname = ''
352                 floatname = ''
353                 readingCiteFormats = False
354                 readingFloat = False
355                 continue
356             if readingCiteFormats:
357                 res = KeyVal.search(line)
358                 if res != None:
359                     val = res.group(1)
360                     if not layouttranslations:
361                         writeString(out, src, base, lineno, val)
362
363     if layouttranslations:
364         # Extract translations of layout files
365         import polib
366
367         # Sort languages and key to minimize the diff between different runs
368         # with changed translations
369         languages.sort()
370         keys = []
371         for key in keyset:
372             keys.append(key)
373         keys.sort()
374
375         ContextRe = re.compile(r'(.*)(\[\[.*\]\])')
376
377         print >> out, '''# This file has been automatically generated by po/lyx_pot.py.
378 # PLEASE MODIFY ONLY THE LAGUAGES HAVING NO .po FILE! If you want to regenerate
379 # this file from the translations, run `make ../lib/layouttranslations' in po.
380 # Python polib library is needed for building the output file.
381 #
382 # This file should remain fixed during minor LyX releases.
383 # For more comments see README.localization file.'''
384         for lang in languages:
385             print >> out, '\nTranslation %s' % lang
386             if lang in oldtrans.keys():
387                 trans = oldtrans[lang]
388             else:
389                 trans = dict()
390             if not lang in oldlanguages:
391                 poname = os.path.join(base, 'po/' + lang + '.po')
392                 po = polib.pofile(poname)
393                 # Iterate through po entries and not keys for speed reasons.
394                 # FIXME: The code is still too slow
395                 for entry in po:
396                     if not entry.translated():
397                         continue
398                     if entry.msgid in keys:
399                         key = entry.msgid
400                         val = entry.msgstr
401                         # some translators keep untranslated entries
402                         if val != key:
403                             trans[key] = val
404             for key in keys:
405                 if key in trans.keys():
406                     val = trans[key].replace('\\', '\\\\').replace('"', '\\"')
407                     res = ContextRe.search(val)
408                     if res != None:
409                         val = res.group(1)
410                     key = key.replace('\\', '\\\\').replace('"', '\\"')
411                     print >> out, '\t"%s" "%s"' % \
412                              (key.encode('utf-8'), val.encode('utf-8'))
413                 # also print untranslated entries to help translators
414                 elif not lang in oldlanguages:
415                     key = key.replace('\\', '\\\\').replace('"', '\\"')
416                     res = ContextRe.search(key)
417                     if res != None:
418                         val = res.group(1)
419                     else:
420                         val = key
421                     print >> out, '\t"%s" "%s"' % \
422                              (key.encode('utf-8'), val.encode('utf-8'))
423             print >> out, 'End'
424
425     out.close()
426
427
428 def qt4_l10n(input_files, output, base):
429     '''Generate pot file from src/frontends/qt4/ui/*.ui'''
430     output = open(output, 'w')
431     pat = re.compile(r'\s*<string>(.*)</string>')
432     prop = re.compile(r'\s*<property.*name.*=.*shortcut')
433     for src in input_files:
434         input = open(src)
435         skipNextLine = False
436         for lineno, line in enumerate(input.readlines()):
437             # skip the line after <property name=shortcut>
438             if skipNextLine:
439                 skipNextLine = False
440                 continue
441             if prop.match(line):
442                 skipNextLine = True
443                 continue
444             # get lines that match <string>...</string>
445             if pat.match(line):
446                 (string,) = pat.match(line).groups()
447                 string = string.replace('&amp;', '&').replace('&quot;', '"')
448                 string = string.replace('&lt;', '<').replace('&gt;', '>')
449                 string = string.replace('\\', '\\\\').replace('"', r'\"')
450                 string = string.replace('&#x0a;', r'\n')
451                 print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
452                     (relativePath(src, base), lineno+1, string)
453         input.close()
454     output.close()
455
456
457 def languages_l10n(input_files, output, base):
458     '''Generate pot file from lib/languages'''
459     out = open(output, 'w')
460     GuiName = re.compile(r'^[^#]*GuiName\s+(.*)', re.IGNORECASE)
461     
462     for src in input_files:
463         descStartLine = -1
464         descLines = []
465         lineno = 0
466         for line in open(src).readlines():
467             lineno += 1
468             res = GuiName.search(line)
469             if res != None:
470                 string = res.group(1)
471                 writeString(out, src, base, lineno, string)
472                 continue
473                
474     out.close()
475
476
477 def latexfonts_l10n(input_files, output, base):
478     '''Generate pot file from lib/latexfonts'''
479     out = open(output, 'w')
480     GuiName = re.compile(r'^[^#]*GuiName\s+(.*)', re.IGNORECASE)
481     
482     for src in input_files:
483         descStartLine = -1
484         descLines = []
485         lineno = 0
486         for line in open(src).readlines():
487             lineno += 1
488             res = GuiName.search(line)
489             if res != None:
490                 string = res.group(1)
491                 writeString(out, src, base, lineno, string)
492                 continue
493                
494     out.close()
495
496
497 def external_l10n(input_files, output, base):
498     '''Generate pot file from lib/external_templates'''
499     output = open(output, 'w')
500     Template = re.compile(r'^Template\s+(.*)', re.IGNORECASE)
501     GuiName = re.compile(r'\s*GuiName\s+(.*)', re.IGNORECASE)
502     HelpTextStart = re.compile(r'\s*HelpText\s', re.IGNORECASE)
503     HelpTextSection = re.compile(r'\s*(\S.*)\s*$')
504     HelpTextEnd = re.compile(r'\s*HelpTextEnd\s', re.IGNORECASE)
505     i = -1
506     for src in input_files:
507         input = open(src)
508         inHelp = False
509         hadHelp = False
510         prev_help_string = ''
511         for lineno, line in enumerate(input.readlines()):
512             if Template.match(line):
513                 (string,) = Template.match(line).groups()
514             elif GuiName.match(line):
515                 (string,) = GuiName.match(line).groups()
516             elif inHelp:
517                 if HelpTextEnd.match(line):
518                     if hadHelp:
519                         print >> output, '\nmsgstr ""\n'
520                     inHelp = False
521                     hadHelp = False
522                     prev_help_string = ''
523                 elif HelpTextSection.match(line):
524                     (help_string,) = HelpTextSection.match(line).groups()
525                     help_string = help_string.replace('"', '')
526                     if help_string != "" and prev_help_string == '':
527                         print >> output, '#: %s:%d\nmsgid ""\n"%s\\n"' % \
528                             (relativePath(src, base), lineno+1, help_string)
529                         hadHelp = True
530                     elif help_string != "":
531                         print >> output, '"%s\\n"' % help_string
532                     prev_help_string = help_string
533             elif HelpTextStart.match(line):
534                 inHelp = True
535                 prev_help_string = ''
536             else:
537                 continue
538             string = string.replace('"', '')
539             if string != "" and not inHelp:
540                 print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
541                     (relativePath(src, base), lineno+1, string)
542         input.close()
543     output.close()
544
545
546 def formats_l10n(input_files, output, base):
547     '''Generate pot file from configure.py'''
548     output = open(output, 'w')
549     GuiName = re.compile(r'.*\\Format\s+\S+\s+\S+\s+"([^"]*)"\s+(\S*)\s+.*', re.IGNORECASE)
550     GuiName2 = re.compile(r'.*\\Format\s+\S+\s+\S+\s+([^"]\S+)\s+(\S*)\s+.*', re.IGNORECASE)
551     input = open(input_files[0])
552     for lineno, line in enumerate(input.readlines()):
553         label = ""
554         labelsc = ""
555         if GuiName.match(line):
556             label = GuiName.match(line).group(1)
557             shortcut = GuiName.match(line).group(2).replace('"', '')
558         elif GuiName2.match(line):
559             label = GuiName2.match(line).group(1)
560             shortcut = GuiName2.match(line).group(2).replace('"', '')
561         else:
562             continue
563         label = label.replace('\\', '\\\\').replace('"', '')
564         if shortcut != "":
565             labelsc = label + "|" + shortcut
566         if label != "":
567             print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
568                 (relativePath(input_files[0], base), lineno+1, label)
569         if labelsc != "":
570             print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
571                 (relativePath(input_files[0], base), lineno+1, labelsc)
572     input.close()
573     output.close()
574
575
576 def encodings_l10n(input_files, output, base):
577     '''Generate pot file from lib/encodings'''
578     output = open(output, 'w')
579     # assuming only one encodings file
580     #                 Encoding utf8      utf8    "Unicode (utf8)" UTF-8    variable inputenc
581     reg = re.compile('Encoding [\w-]+\s+[\w-]+\s+"([\w \-\(\)]+)"\s+[\w-]+\s+(fixed|variable|variableunsafe)\s+\w+.*')
582     input = open(input_files[0])
583     for lineno, line in enumerate(input.readlines()):
584         if not line.startswith('Encoding'):
585             continue
586         if reg.match(line):
587             print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % \
588                 (relativePath(input_files[0], base), lineno+1, reg.match(line).groups()[0])
589         else:
590             print "Error: Unable to handle line:"
591             print line
592             # No need to abort if the parsing fails
593             # sys.exit(1)
594     input.close()
595     output.close()
596
597
598
599 Usage = '''
600 lyx_pot.py [-b|--base top_src_dir] [-o|--output output_file] [-h|--help] [-s|src_file filename] -t|--type input_type input_files
601
602 where
603     --base:
604         path to the top source directory. default to '.'
605     --output:
606         output pot file, default to './lyx.pot'
607     --src_file
608         filename that contains a list of input files in each line
609     --input_type can be
610         ui: lib/ui/*
611         layouts: lib/layouts/*
612         layouttranslations: create lib/layouttranslations from po/*.po and lib/layouts/*
613         qt4: qt4 ui files
614         languages: file lib/languages
615         latexfonts: file lib/latexfonts
616         encodings: file lib/encodings
617         external: external templates file
618         formats: formats predefined in lib/configure.py
619 '''
620
621 if __name__ == '__main__':
622     input_type = None
623     output = 'lyx.pot'
624     base = '.'
625     input_files = []
626     #
627     optlist, args = getopt.getopt(sys.argv[1:], 'ht:o:b:s:',
628         ['help', 'type=', 'output=', 'base=', 'src_file='])
629     for (opt, value) in optlist:
630         if opt in ['-h', '--help']:
631             print Usage
632             sys.exit(0)
633         elif opt in ['-o', '--output']:
634             output = value
635         elif opt in ['-b', '--base']:
636             base = value
637         elif opt in ['-t', '--type']:
638             input_type = value
639         elif opt in ['-s', '--src_file']:
640             input_files = [f.strip() for f in open(value)]
641
642     if input_type not in ['ui', 'layouts', 'layouttranslations', 'qt4', 'languages', 'latexfonts', 'encodings', 'external', 'formats'] or output is None:
643         print 'Wrong input type or output filename.'
644         sys.exit(1)
645
646     input_files += args
647
648     if input_type == 'ui':
649         ui_l10n(input_files, output, base)
650     elif input_type == 'latexfonts':
651         latexfonts_l10n(input_files, output, base)
652     elif input_type == 'layouts':
653         layouts_l10n(input_files, output, base, False)
654     elif input_type == 'layouttranslations':
655         layouts_l10n(input_files, output, base, True)
656     elif input_type == 'qt4':
657         qt4_l10n(input_files, output, base)
658     elif input_type == 'external':
659         external_l10n(input_files, output, base)
660     elif input_type == 'formats':
661         formats_l10n(input_files, output, base)
662     elif input_type == 'encodings':
663         encodings_l10n(input_files, output, base)
664     else:
665         languages_l10n(input_files, output, base)
666
667