Ejemplo n.º 1
0
def convertoo(inputfile, outputfile, templatefile, sourcelanguage=None,
              targetlanguage=None, timestamp=None, includefuzzy=False,
              multifilestyle="single", skip_source=False, filteraction=None,
              outputthreshold=None):
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    inputstore.filename = getattr(inputfile, 'name', '')
    if not targetlanguage:
        raise ValueError("You must specify the target language")
    if not sourcelanguage:
        if targetlanguage.isdigit():
            sourcelanguage = "01"
        else:
            sourcelanguage = "en-US"
    languages = (sourcelanguage, targetlanguage)
    if templatefile is None:
        raise ValueError("must have template file for oo files")
    else:
        convertor = reoo(templatefile, languages=languages,
                         timestamp=timestamp, includefuzzy=includefuzzy,
                         long_keys=multifilestyle != "single",
                         filteraction=filteraction)
    outputstore = convertor.convertstore(inputstore)
    # TODO: check if we need to manually delete missing items
    outputfile.write(outputstore.__str__(skip_source, targetlanguage))
    return True
Ejemplo n.º 2
0
def convertdtd(inputfile, outputfile, templatefile, includefuzzy=False,
               remove_untranslated=False, outputthreshold=None):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    # Some of the DTD files used for Firefox Mobile are actually completely
    # different with different escaping and quoting rules. The best way to
    # identify them seems to be on their file path in the tree (based on code
    # in compare-locales).
    android_dtd = False
    header_comment = ""
    input_header = inputstore.header()
    if input_header:
        header_comment = input_header.getnotes("developer")
        if "embedding/android" in header_comment or "mobile/android/base" in header_comment:
            android_dtd = True

    if templatefile is None:
        convertor = po2dtd(android=android_dtd,
                           remove_untranslated=remove_untranslated)
    else:
        templatestore = dtd.dtdfile(templatefile, android=android_dtd)
        convertor = redtd(templatestore, android=android_dtd,
                          remove_untranslated=remove_untranslated)
    outputstore = convertor.convertstore(inputstore, includefuzzy)
    outputfile.write(str(outputstore))
    return 1
Ejemplo n.º 3
0
def convertpy(inputfile, outputfile, templatefile=None, includefuzzy=False,
              outputthreshold=None):
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    convertor = po2pydict()
    outputstring = convertor.convertstore(inputstore, includefuzzy)
    outputfile.write(outputstring.read())
    return 1
Ejemplo n.º 4
0
def convertical(inputfile, outputfile, templatefile, includefuzzy=False, outputthreshold=None):
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if templatefile is None:
        raise ValueError("must have template file for iCal files")
    else:
        convertor = reical(templatefile, inputstore)
    outputstring = convertor.convertstore(includefuzzy)
    outputfile.write(outputstring)
    return 1
Ejemplo n.º 5
0
def convertsub(inputfile, outputfile, templatefile, includefuzzy=False,
               outputthreshold=None):
    if templatefile is None:
        raise ValueError("must have template file for subtitle files")

    inputstore = po.pofile(inputfile)
    if not convert.should_output_store(inputstore, outputthreshold):
        return 0

    convertor = po2sub(templatefile, inputstore, includefuzzy)
    outputstring = convertor.convert_store()
    outputfile.write(outputstring)
    return 1
Ejemplo n.º 6
0
def convertphp(inputfile, outputfile, templatefile, includefuzzy=False,
               outputthreshold=None):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if templatefile is None:
        raise ValueError("must have template file for php files")

    convertor = rephp(templatefile, inputstore)
    outputphplines = convertor.convertstore(includefuzzy)
    outputfile.writelines(outputphplines)
    return 1
Ejemplo n.º 7
0
def convertjson(inputfile, outputfile, templatefile, includefuzzy=False,
                outputthreshold=None, remove_untranslated=False):
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if templatefile is None:
        raise ValueError("Must have template file for JSON files")

    convertor = rejson(templatefile, inputstore)
    outputstring = convertor.convertstore(includefuzzy, remove_untranslated)
    outputfile.write(outputstring)
    return True
Ejemplo n.º 8
0
def convertlang(inputfile, outputfile, templates, includefuzzy=False, mark_active=True,
                outputthreshold=None):
    """reads in stdin using fromfileclass, converts using convertorclass,
    writes to stdout"""
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if inputstore.isempty():
        return 0
    convertor = po2lang(mark_active=mark_active)
    outputstore = convertor.convertstore(inputstore, includefuzzy)
    outputfile.write(str(outputstore))
    return 1
Ejemplo n.º 9
0
def convertpy(inputfile, outputfile, templatefile=None, includefuzzy=False,
              outputthreshold=None):
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return 0

    convertor = po2pydict()
    outputstring = convertor.convertstore(inputstore, includefuzzy)

    if six.PY2:
        outputfile.write(outputstring.read().decode('utf-8'))
    else:
        outputfile.write(bytes(outputstring.read(), 'utf-8'))
    return 1
Ejemplo n.º 10
0
    def __init__(self, input_file, output_file, template_file=None,
                 include_fuzzy=False, output_threshold=None, encoding='utf-8',
                 wrap=None):
        """Initialize the converter."""
        self.source_store = factory.getobject(input_file)

        self.should_output_store = convert.should_output_store(
            self.source_store, output_threshold
        )
        if self.should_output_store:
            self.include_fuzzy = include_fuzzy
            self.encoding = encoding
            self.wrap = wrap

            self.output_file = output_file
            self.template_file = template_file
Ejemplo n.º 11
0
def converttxt(inputfile, outputfile, templatefile, wrap=None, includefuzzy=False, encoding='utf-8',
               outputthreshold=None):
    """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    convertor = po2txt(wrap=wrap)
    if templatefile is None:
        outputstring = convertor.convertstore(inputstore, includefuzzy)
    else:
        templatestring = templatefile.read().decode(encoding)
        outputstring = convertor.mergestore(inputstore, templatestring, includefuzzy)
    outputfile.write(outputstring.encode('utf-8'))
    return 1
Ejemplo n.º 12
0
def convertprop(inputfile, outputfile, templatefile, personality="java",
                includefuzzy=False, encoding=None, remove_untranslated=False,
                outputthreshold=None):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if templatefile is None:
        raise ValueError("must have template file for properties files")
        # convertor = po2prop()
    else:
        convertor = reprop(templatefile, inputstore, personality, encoding,
                           remove_untranslated)
    outputprop = convertor.convertstore(includefuzzy)
    outputfile.write(outputprop)
    return 1
Ejemplo n.º 13
0
def convertrc(inputfile, outputfile, templatefile, includefuzzy=False,
              charset=None, lang=None, sublang=None, outputthreshold=None):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if not lang:
        raise ValueError("must specify a target language")
    if templatefile is None:
        raise ValueError("must have template file for rc files")
        # convertor = po2rc()
    else:
        convertor = rerc(templatefile, charset, lang, sublang)
    outputrclines = convertor.convertstore(inputstore, includefuzzy)
    outputfile.writelines(outputrclines)
    return 1
Ejemplo n.º 14
0
    def __init__(self, input_file, output_file, template_file=None,
                 include_fuzzy=False, output_threshold=None):
        """Initialize the converter."""
        if template_file is None:
            raise ValueError(self.MissingTemplateMessage)

        self.source_store = self.SourceStoreClass(input_file)
        self.target_store = self.TargetStoreClass()

        self.should_output_store = convert.should_output_store(
            self.source_store, output_threshold
        )
        if self.should_output_store:
            self.include_fuzzy = include_fuzzy

            self.output_file = output_file
            self.template_store = self.TargetStoreClass(template_file)
Ejemplo n.º 15
0
def converthtml(inputfile, outputfile, templatefile, includefuzzy=False,
                outputthreshold=None):
    """reads in stdin using fromfileclass, converts using convertorclass,
    writes to stdout"""
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    convertor = po2html()
    if templatefile is None:
        raise ValueError("must have template file for HTML files")
    else:
        outputstring = convertor.mergestore(inputstore, templatefile,
                                            includefuzzy)
    outputfile.write(outputstring.encode('utf-8'))
    return 1
Ejemplo n.º 16
0
def convertoo(inputfile,
              outputfile,
              templatefile,
              sourcelanguage=None,
              targetlanguage=None,
              timestamp=None,
              includefuzzy=False,
              multifilestyle="single",
              skip_source=False,
              filteraction=None,
              outputthreshold=None):
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    inputstore.filename = getattr(inputfile, 'name', '')
    if not targetlanguage:
        raise ValueError("You must specify the target language")
    if not sourcelanguage:
        if targetlanguage.isdigit():
            sourcelanguage = "01"
        else:
            sourcelanguage = "en-US"
    languages = (sourcelanguage, targetlanguage)
    if templatefile is None:
        raise ValueError("must have template file for oo files")
    else:
        convertor = reoo(templatefile,
                         languages=languages,
                         timestamp=timestamp,
                         includefuzzy=includefuzzy,
                         long_keys=multifilestyle != "single",
                         filteraction=filteraction)
    outputstore = convertor.convertstore(inputstore)
    # TODO: check if we need to manually delete missing items
    outputfile.write(outputstore.__str__(skip_source, targetlanguage))
    return True
Ejemplo n.º 17
0
    def __init__(self, input_file, output_file, template_file=None,
                 include_fuzzy=False, output_threshold=None,
                 dialect="default"):
        """Initialize the converter."""
        if ini.INIConfig is None:
            print("Missing iniparse library!")
            sys.exit()

        if template_file is None:
            raise ValueError(self.MissingTemplateMessage)

        self.source_store = self.SourceStoreClass(input_file)

        self.should_output_store = convert.should_output_store(
            self.source_store, output_threshold
        )
        if self.should_output_store:
            self.include_fuzzy = include_fuzzy

            self.output_file = output_file
            self.template_store = self.TargetStoreClass(template_file,
                                                        dialect=dialect)
            self.target_store = self.TargetStoreClass(dialect=dialect)
Ejemplo n.º 18
0
def convertrc(inputfile, outputfile, templatefile, includefuzzy=False,
              charset=None, lang=None, sublang=None, outputthreshold=None):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if not lang:
        raise ValueError("must specify a target language")
    if templatefile is None:
        raise ValueError("must have template file for rc files")
        # convertor = po2rc()
    else:
        convertor = rerc(templatefile, charset, lang, sublang)
    outputrclines = convertor.convertstore(inputstore, includefuzzy)
    try:
        outputfile.write(outputrclines.encode('cp1252'))
    except UnicodeEncodeError:
        outputfile.write(codecs.BOM_UTF16_LE)
        outputfile.write(outputrclines.encode('utf-16-le'))
    outputfile.close()
    templatefile.close()
    return 1
Ejemplo n.º 19
0
def convertrc(inputfile,
              outputfile,
              templatefile,
              includefuzzy=False,
              charset=None,
              lang=None,
              sublang=None,
              outputthreshold=None):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if not lang:
        raise ValueError("must specify a target language")
    if templatefile is None:
        raise ValueError("must have template file for rc files")
        # convertor = po2rc()
    else:
        convertor = rerc(templatefile, charset, lang, sublang)
    outputrclines = convertor.convertstore(inputstore, includefuzzy)
    outputfile.writelines(outputrclines)
    return 1
Ejemplo n.º 20
0
    def __init__(self, input_file, output_file, template_file=None,
                 include_fuzzy=False, output_threshold=None,
                 dialect="default"):
        """Initialize the converter."""
        if ini.INIConfig is None:
            print("Missing iniparse library!")
            sys.exit()

        if template_file is None:
            raise ValueError(self.MissingTemplateMessage)

        self.source_store = self.SourceStoreClass(input_file)

        self.should_output_store = convert.should_output_store(
            self.source_store, output_threshold
        )
        if self.should_output_store:
            self.include_fuzzy = include_fuzzy

            self.output_file = output_file
            self.template_store = self.TargetStoreClass(template_file,
                                                        dialect=dialect)
            self.target_store = self.TargetStoreClass(dialect=dialect)
Ejemplo n.º 21
0
def convertdtd(
    inputfile,
    outputfile,
    templatefile,
    includefuzzy=False,
    remove_untranslated=False,
    outputthreshold=None,
):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    # Some of the DTD files used for Firefox Mobile are actually completely
    # different with different escaping and quoting rules. The best way to
    # identify them seems to be on their file path in the tree (based on code
    # in compare-locales).
    android_dtd = False
    header_comment = ""
    input_header = inputstore.header()
    if input_header:
        header_comment = input_header.getnotes("developer")
        if ("embedding/android" in header_comment
                or "mobile/android/base" in header_comment):
            android_dtd = True

    if templatefile is None:
        convertor = po2dtd(android=android_dtd,
                           remove_untranslated=remove_untranslated)
    else:
        templatestore = dtd.dtdfile(templatefile, android=android_dtd)
        convertor = redtd(templatestore,
                          android=android_dtd,
                          remove_untranslated=remove_untranslated)
    outputstore = convertor.convertstore(inputstore, includefuzzy)
    outputstore.serialize(outputfile)
    return 1
Ejemplo n.º 22
0
def converttxt(inputfile,
               outputfile,
               templatefile,
               wrap=None,
               includefuzzy=False,
               encoding='utf-8',
               outputthreshold=None):
    """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout"""
    inputstore = factory.getobject(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    convertor = po2txt(wrap=wrap)

    if templatefile is None:
        outputstring = convertor.convertstore(inputstore, includefuzzy)
    else:
        templatestring = templatefile.read().decode(encoding)
        outputstring = convertor.mergestore(inputstore, templatestring,
                                            includefuzzy)

    outputfile.write(outputstring.encode('utf-8'))
    return True
Ejemplo n.º 23
0
    def __init__(self,
                 input_file,
                 output_file,
                 template_file=None,
                 include_fuzzy=False,
                 output_threshold=None):
        """Initialize the converter."""

        if template_file is None:
            raise ValueError(self.MissingTemplateMessage)

        self.source_store = self.SourceStoreClass(input_file)

        self.should_output_store = convert.should_output_store(
            self.source_store, output_threshold)
        if self.should_output_store:
            self.include_fuzzy = include_fuzzy
            self.output_threshold = output_threshold

            self.output_file = output_file
            self.template_store = self.TargetStoreClass(template_file)
            self.target_store = self.TargetStoreClass()

            self.source_store.makeindex()
Ejemplo n.º 24
0
def convertprop(
    inputfile,
    outputfile,
    templatefile,
    personality="java",
    includefuzzy=False,
    encoding=None,
    remove_untranslated=False,
    outputthreshold=None,
):
    inputstore = po.pofile(inputfile)

    if not convert.should_output_store(inputstore, outputthreshold):
        return False

    if templatefile is None:
        raise ValueError("must have template file for properties files")
        # convertor = po2prop()
    else:
        convertor = reprop(templatefile, inputstore, personality, encoding,
                           remove_untranslated)
    outputprop = convertor.convertstore(includefuzzy)
    outputfile.write(outputprop)
    return True