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