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 -def main(argv=None):
    35      formats = {(None, "*"): ("*", convert.copytemplate),
    36              ("*", "*"): ("*", convert.copyinput),
    37              "*": ("*", convert.copyinput)}
    38      # handle formats that convert to .po files
    39      converters = [("dtd", dtd2po.convertdtd), ("properties", prop2po.convertmozillaprop),
    40              ("it", mozfunny2prop.it2po), ("ini", mozfunny2prop.ini2po), ("inc", mozfunny2prop.inc2po)]
    41      for format, converter in converters:
    42          formats[(format, format)] = (format + ".po", converter)
    43          formats[format] = (format + ".po", converter)
    44      # handle search and replace
    45      replacer = convert.Replacer("en-US", "${locale}")
    46      for replaceformat in ("js", "rdf", "manifest"):
    47          formats[(None, replaceformat)] = (replaceformat, replacer.searchreplacetemplate)
    48          formats[(replaceformat, replaceformat)] = (replaceformat, replacer.searchreplaceinput)
    49          formats[replaceformat] = (replaceformat, replacer.searchreplaceinput)
    50      parser = convert.ArchiveConvertOptionParser(formats, usetemplates=True, usepots=True, description=__doc__, archiveformats={"xpi": xpi.XpiFile})
    51      parser.add_duplicates_option()
    52      parser.passthrough.append("pot")
    53      parser.run(argv)
    54
    55
    56  if __name__ == '__main__':
    57      main()
    58