Example #1
0
    def test_parse_locations(self):
        """
        This function will test to make sure the location matching is working.  It
        tests that locations are detected, the default "translated" case, and that
        "unused" lines can start with //
        """
        tikisource = b"""
"zero_source" => "zero_target",
// ### Start of unused words
"one_source" => "one_target",
// ### end of unused words
"two_source" => "two_target",
// ### start of untranslated words
// "three_source" => "three_target",
// ### end of untranslated words
"four_source" => "four_target",
// ### start of possibly untranslated words
"five_source" => "five_target",
// ### end of possibly untranslated words
"six_source" => "six_target",
        """
        tikifile = tiki.TikiStore(tikisource)
        assert len(tikifile.units) == 7
        assert tikifile.units[0].location == ["translated"]
        assert tikifile.units[1].location == ["unused"]
        assert tikifile.units[2].location == ["translated"]
        assert tikifile.units[3].location == ["untranslated"]
        assert tikifile.units[4].location == ["translated"]
        assert tikifile.units[5].location == ["possiblyuntranslated"]
        assert tikifile.units[6].location == ["translated"]
Example #2
0
    def test_parse_ignore_extras(self):
        """Tests that we ignore extraneous lines"""
        tikisource = b"""<?php
$lang = Array(
"zero_source" => "zero_target",
// ###
// this is a blank line:

"###end###"=>"###end###");
        """
        tikifile = tiki.TikiStore(tikisource)
        assert len(tikifile.units) == 1
        assert tikifile.units[0].source == "zero_source"
        assert tikifile.units[0].target == "zero_target"
def converttiki(inputfile, outputfile, template=None, includeunused=False):
    """Converts from tiki file format to po.

    @param inputfile: file handle of the source
    @param outputfile: file handle to write to
    @param template: unused
    @param includeunused: Include the "usused" section of the tiki file? Default: False
    """
    convertor = tiki2po(includeunused=includeunused)
    inputstore = tiki.TikiStore(inputfile)
    outputstore = convertor.convertstore(inputstore)
    if outputstore.isempty():
        return False
    outputfile.write(str(outputstore))
    return True
Example #4
0
    def convertstore(self, thepofile):
        """Converts a given (parsed) po file to a tiki file.

        :param thepofile: a pofile pre-loaded with input data
        """
        thetargetfile = tiki.TikiStore()
        for unit in thepofile.units:
            if not (unit.isblank() or unit.isheader()):
                newunit = tiki.TikiUnit(unit.source)
                newunit.target = unit.target
                locations = unit.getlocations()
                if locations:
                    newunit.addlocations(locations)
                # If a word is "untranslated" but the target isn't empty and isn't the same as the source
                # it's been translated and we switch it. This is an assumption but should remain true as long
                # as these scripts are used.
                if newunit.getlocations() == ["untranslated"] and unit.source != unit.target and unit.target != "":
                    newunit.location = []
                    newunit.addlocation("translated")

                thetargetfile.addunit(newunit)
        return thetargetfile
Example #5
0
 def test_parse_encode(self):
     """Make sure these tiki special symbols come through correctly"""
     tikisource = br'"test: |\n \r \t \\ \$ \"|" => "test: |\n \r \t \\ \$ \"|",'
     tikifile = tiki.TikiStore(tikisource)
     assert tikifile.units[0].source == r"test: |\n \r \t \\ \$ \"|"
     assert tikifile.units[0].target == r"test: |\n \r \t \\ \$ \"|"
Example #6
0
 def test_parse_simple(self):
     tikisource = br'"Top authors" => "Top autoren",'
     tikifile = tiki.TikiStore(tikisource)
     assert len(tikifile.units) == 1
     assert tikifile.units[0].source == "Top authors"
     assert tikifile.units[0].target == "Top autoren"