Package translate :: Package convert :: Module moz2po

[hide private]
[frames] | no frames]

# Source Code for Module translate.convert.moz2po

     1  #!/usr/bin/env python
     2  # -*- coding: utf-8 -*-
     3  #
     4  # Copyright 2004-2006 Zuza Software Foundation
     5  #
     6  # This file is part of translate.
     7  #
     8  # translate 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  # translate 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 translate; if not, write to the Free Software
    20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    21
    22  """convert Mozilla .dtd and .properties files to Gettext PO localization files
    23
    24  See: http://translate.sourceforge.net/wiki/toolkit/moz2po for examples and
    25  usage instructions
    26  """
    27
    28  from translate.convert import dtd2po
    29  from translate.convert import prop2po
    30  from translate.convert import mozfunny2prop
    31  from translate.storage import xpi
    32  from translate.convert import convert
    33
    34
    35 -def main(argv=None):
    36      formats = {(None, "*"): ("*", convert.copytemplate),
    37                 ("*", "*"): ("*", convert.copyinput),
    38                 "*": ("*", convert.copyinput),
    39                }
    40      # handle formats that convert to .po files
    41      converters = [("dtd", dtd2po.convertdtd),
    42                    ("properties", prop2po.convertmozillaprop),
    43                    ("it", mozfunny2prop.it2po),
    44                    ("ini", mozfunny2prop.ini2po),
    45                    ("inc", mozfunny2prop.inc2po),
    46                   ]
    47      for format, converter in converters:
    48          formats[(format, format)] = (format + ".po", converter)
    49          formats[format] = (format + ".po", converter)
    50      # handle search and replace
    51      replacer = convert.Replacer("en-US", "${locale}")
    52      for replaceformat in ("js", "rdf", "manifest"):
    53          formats[(None, replaceformat)] = (replaceformat,
    54                                            replacer.searchreplacetemplate)
    55          formats[(replaceformat, replaceformat)] = (replaceformat,
    56                                                     replacer.searchreplaceinput)
    57          formats[replaceformat] = (replaceformat, replacer.searchreplaceinput)
    58      parser = convert.ArchiveConvertOptionParser(formats, usetemplates=True,
    59                                                  usepots=True,
    60                                                  description=__doc__,
    61                                                  archiveformats={"xpi": xpi.XpiFile})
    62      parser.add_duplicates_option()
    63      parser.passthrough.append("pot")
    64      parser.run(argv)
    65
    66
    67  if __name__ == '__main__':
    68      main()
    69