コード例 #1
0
ファイル: test_dtd2po.py プロジェクト: anderson916/translate
 def dtd2po(self, dtdsource, dtdtemplate=None):
     """helper that converts dtd source to po source without requiring files"""
     inputfile = wStringIO.StringIO(dtdsource)
     inputdtd = dtd.dtdfile(inputfile)
     convertor = dtd2po.dtd2po()
     if dtdtemplate is None:
         outputpo = convertor.convertstore(inputdtd)
     else:
         templatefile = wStringIO.StringIO(dtdtemplate)
         templatedtd = dtd.dtdfile(templatefile)
         outputpo = convertor.mergestore(templatedtd, inputdtd)
     return outputpo
コード例 #2
0
ファイル: dtd2po.py プロジェクト: AlexArgus/affiliates-lib
def convertdtd(inputfile, outputfile, templatefile, pot=False, duplicatestyle="msgctxt"):
    """reads in inputfile and templatefile using dtd, converts using dtd2po, writes to outputfile"""
    inputstore = dtd.dtdfile(inputfile)
    convertor = dtd2po(blankmsgstr=pot, duplicatestyle=duplicatestyle)
    if templatefile is None:
        outputstore = convertor.convertstore(inputstore)
    else:
        templatestore = dtd.dtdfile(templatefile)
        outputstore = convertor.mergestore(templatestore, inputstore)
    if outputstore.isempty():
        return 0
    outputfile.write(str(outputstore))
    return 1
コード例 #3
0
ファイル: po2dtd.py プロジェクト: onia/translate
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
コード例 #4
0
ファイル: test_dtd.py プロジェクト: Jobava/translate-toolkit
 def dtdparse(self, dtdsource):
     """helper that parses dtd source without requiring files"""
     if not isinstance(dtdsource, bytes):
         dtdsource = dtdsource.encode('utf-8')
     dummyfile = BytesIO(dtdsource)
     dtdfile = dtd.dtdfile(dummyfile)
     return dtdfile
コード例 #5
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 = u""
    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
コード例 #6
0
 def dtdparse(self, dtdsource):
     """helper that parses dtd source without requiring files"""
     if not isinstance(dtdsource, bytes):
         dtdsource = dtdsource.encode('utf-8')
     dummyfile = BytesIO(dtdsource)
     dtdfile = dtd.dtdfile(dummyfile)
     return dtdfile
コード例 #7
0
def convertdtd(inputfile,
               outputfile,
               templatefile,
               pot=False,
               duplicatestyle="msgctxt"):
    """reads in inputfile and templatefile using dtd, converts using dtd2po, writes to outputfile"""
    inputstore = dtd.dtdfile(inputfile)
    convertor = dtd2po(blankmsgstr=pot, duplicatestyle=duplicatestyle)
    if templatefile is None:
        outputstore = convertor.convertstore(inputstore)
    else:
        templatestore = dtd.dtdfile(templatefile)
        outputstore = convertor.mergestore(templatestore, inputstore)
    if outputstore.isempty():
        return 0
    outputfile.write(str(outputstore))
    return 1
コード例 #8
0
 def merge2dtd(dtdsource, posource):
     """helper that merges po translations to dtd source without requiring files"""
     inputfile = BytesIO(posource.encode())
     inputpo = po.pofile(inputfile)
     templatefile = BytesIO(dtdsource.encode())
     templatedtd = dtd.dtdfile(templatefile)
     convertor = po2dtd.redtd(templatedtd)
     return convertor.convertstore(inputpo)
コード例 #9
0
ファイル: dtd2lang.py プロジェクト: gialloporpora/yellowpy
def openDTD(file):
	f = open(file, "r")
	dtdobj = dtd.dtdfile(f)
	f.close()
	dtdentries = dtdobj.units
	d = OrderedDict()
	for i in dtdentries:
		if d.has_key(i.entity): print "Duplicate entry: %s" %i.entity
		else: d[i.entity] = dtd.unquotefromdtd(i.definition)
コード例 #10
0
    def dtdparse(self, dtdsource):
        """Parses an Android DTD source string and returns a DTD store.

        This allows to simulate reading from Android DTD files without really
        having real Android DTD files.
        """
        dummyfile = wStringIO.StringIO(dtdsource)
        dtdfile = dtd.dtdfile(dummyfile, android=True)
        return dtdfile
コード例 #11
0
ファイル: test_po2dtd.py プロジェクト: cloph/translate
 def merge2dtd(self, dtdsource, posource):
     """helper that merges po translations to dtd source without requiring files"""
     inputfile = wStringIO.StringIO(posource)
     inputpo = po.pofile(inputfile)
     templatefile = wStringIO.StringIO(dtdsource)
     templatedtd = dtd.dtdfile(templatefile)
     convertor = po2dtd.redtd(templatedtd)
     outputdtd = convertor.convertstore(inputpo)
     return outputdtd
コード例 #12
0
ファイル: test_po2dtd.py プロジェクト: ANKIT-KS/fjord
 def merge2dtd(self, dtdsource, posource):
     """helper that merges po translations to dtd source without requiring files"""
     inputfile = wStringIO.StringIO(posource)
     inputpo = po.pofile(inputfile)
     templatefile = wStringIO.StringIO(dtdsource)
     templatedtd = dtd.dtdfile(templatefile)
     convertor = po2dtd.redtd(templatedtd)
     outputdtd = convertor.convertstore(inputpo)
     return outputdtd
コード例 #13
0
ファイル: po2dtd.py プロジェクト: asyschikov/translate
 def convertstore(self, inputstore, includefuzzy=False):
     outputstore = dtd.dtdfile(android=self.android)
     self.currentgroups = []
     for inputunit in inputstore.units:
         if (includefuzzy or not inputunit.isfuzzy()) and (inputunit.istranslated() or not self.remove_untranslated):
             dtdunit = self.convertunit(inputunit)
             if dtdunit is not None:
                 outputstore.addunit(dtdunit)
     return outputstore
コード例 #14
0
ファイル: po2dtd.py プロジェクト: AlexArgus/affiliates-lib
 def convertstore(self, inputstore, includefuzzy=False):
     outputstore = dtd.dtdfile()
     self.currentgroups = []
     for inputunit in inputstore.units:
         if includefuzzy or not inputunit.isfuzzy():
             dtdunit = self.convertunit(inputunit)
             if dtdunit is not None:
                 outputstore.addunit(dtdunit)
     return outputstore
コード例 #15
0
ファイル: po2dtd.py プロジェクト: zbj00/translate
 def convertstore(self, inputstore, includefuzzy=False):
     outputstore = dtd.dtdfile(android=self.android)
     self.currentgroups = []
     for inputunit in inputstore.units:
         if includefuzzy or not inputunit.isfuzzy():
             dtdunit = self.convertunit(inputunit)
             if dtdunit is not None:
                 outputstore.addunit(dtdunit)
     return outputstore
コード例 #16
0
ファイル: test_dtd.py プロジェクト: anderson916/translate
    def dtdparse(self, dtdsource):
        """Parses an Android DTD source string and returns a DTD store.

        This allows to simulate reading from Android DTD files without really
        having real Android DTD files.
        """
        dummyfile = wStringIO.StringIO(dtdsource)
        dtdfile = dtd.dtdfile(dummyfile, android=True)
        return dtdfile
コード例 #17
0
ファイル: po2dtd.py プロジェクト: AlexArgus/affiliates-lib
def convertdtd(inputfile, outputfile, templatefile, includefuzzy=False):
    inputstore = po.pofile(inputfile)
    if templatefile is None:
        convertor = po2dtd()
    else:
        templatestore = dtd.dtdfile(templatefile)
        convertor = redtd(templatestore)
    outputstore = convertor.convertstore(inputstore, includefuzzy)
    outputfile.write(str(outputstore))
    return 1
コード例 #18
0
ファイル: po2dtd.py プロジェクト: mozilla/markup-lib
def convertdtd(inputfile, outputfile, templatefile, includefuzzy=False):
    inputstore = po.pofile(inputfile)
    if templatefile is None:
        convertor = po2dtd()
    else:
        templatestore = dtd.dtdfile(templatefile)
        convertor = redtd(templatestore)
    outputstore = convertor.convertstore(inputstore, includefuzzy)
    outputfile.write(str(outputstore))
    return 1
コード例 #19
0
ファイル: test_dtd.py プロジェクト: nijel/translate
    def dtdparse(dtdsource):
        """Parses an Android DTD source string and returns a DTD store.

        This allows to simulate reading from Android DTD files without really
        having real Android DTD files.
        """
        if not isinstance(dtdsource, bytes):
            dtdsource = dtdsource.encode("utf-8")
        dummyfile = BytesIO(dtdsource)
        return dtd.dtdfile(dummyfile, android=True)
コード例 #20
0
ファイル: test_dtd.py プロジェクト: Jobava/translate-toolkit
    def dtdparse(self, dtdsource):
        """Parses an Android DTD source string and returns a DTD store.

        This allows to simulate reading from Android DTD files without really
        having real Android DTD files.
        """
        if not isinstance(dtdsource, bytes):
            dtdsource = dtdsource.encode('utf-8')
        dummyfile = BytesIO(dtdsource)
        dtdfile = dtd.dtdfile(dummyfile, android=True)
        return dtdfile
コード例 #21
0
ファイル: dtd2po.py プロジェクト: alghaamdi/translate
def convertdtd(inputfile, outputfile, templatefile, pot=False,
               duplicatestyle="msgctxt"):
    """reads in inputfile and templatefile using dtd, converts using dtd2po,
    writes to outputfile"""
    android_dtd = False
    if hasattr(inputfile, "name"):
        # Check if it is an Android DTD file.
        if ("embedding/android" in inputfile.name or
            "mobile/android/base" in inputfile.name):
            android_dtd = True
    inputstore = dtd.dtdfile(inputfile, android=android_dtd)
    convertor = dtd2po(blankmsgstr=pot, duplicatestyle=duplicatestyle)
    if templatefile is None:
        outputstore = convertor.convertstore(inputstore)
    else:
        templatestore = dtd.dtdfile(templatefile, android=android_dtd)
        outputstore = convertor.mergestore(templatestore, inputstore)
    if outputstore.isempty():
        return 0
    outputfile.write(str(outputstore))
    return 1
コード例 #22
0
def convertdtd(inputfile, outputfile, templatefile, pot=False,
               duplicatestyle="msgctxt"):
    """reads in inputfile and templatefile using dtd, converts using dtd2po,
    writes to outputfile"""
    android_dtd = False
    if hasattr(inputfile, "name"):
        # Check if it is an Android DTD file.
        if ("embedding/android" in inputfile.name or
            "mobile/android/base" in inputfile.name):
            android_dtd = True
    inputstore = dtd.dtdfile(inputfile, android=android_dtd)
    convertor = dtd2po(blankmsgstr=pot, duplicatestyle=duplicatestyle)
    if templatefile is None:
        outputstore = convertor.convertstore(inputstore)
    else:
        templatestore = dtd.dtdfile(templatefile, android=android_dtd)
        outputstore = convertor.mergestore(templatestore, inputstore)
    if outputstore.isempty():
        return 0
    outputfile.write(str(outputstore))
    return 1
コード例 #23
0
 def dtdparse(self, dtdsource):
     """helper that parses dtd source without requiring files"""
     dummyfile = wStringIO.StringIO(dtdsource)
     dtdfile = dtd.dtdfile(dummyfile)
     return dtdfile
コード例 #24
0
ファイル: test_dtd.py プロジェクト: anderson916/translate
 def dtdparse(self, dtdsource):
     """helper that parses dtd source without requiring files"""
     dummyfile = wStringIO.StringIO(dtdsource)
     dtdfile = dtd.dtdfile(dummyfile)
     return dtdfile