示例#1
0
def process_projects(src_directory, trg_directory):
    json = JsonBackend("../cfg/projects/")
    json.load()

    projects = sorted(json.projects, key=lambda x: x.name.lower())
    for project_dto in projects:
        if project_dto.downloadable:

            src_file = os.path.join(src_directory, project_dto.filename)
            trg_file = os.path.join(trg_directory, project_dto.filename)

            if os.path.isfile(src_file) and not os.path.isfile(trg_file):
                print("{0} is missing in the new version".format(
                    project_dto.filename))

            if not os.path.isfile(src_file) and os.path.isfile(trg_file):
                print("{0} has been added in the new version".format(
                    project_dto.filename))

            src_stats = POFile(src_file).get_statistics()
            trg_stats = POFile(trg_file).get_statistics()

            print(
                "{0} project: {1} words (before), {2} words (now), delta {3}".
                format(project_dto.filename, src_stats, trg_stats,
                       trg_stats - src_stats))
示例#2
0
    def test_remove_untranslated_strings(self):
        tmpfile = tempfile.NamedTemporaryFile()
        filename = tmpfile.name + ".po"
        self._create_po_with_untranslated_strings(filename)

        poFile = POFile(filename)
        poFile._remove_untranslated_strings()

        po = polib.pofile(filename)
        self.assertEquals(1, len(po))
示例#3
0
    def test_remove_untranslated_strings(self):
        tmpfile = tempfile.NamedTemporaryFile()
        filename = tmpfile.name + ".po"
        self._create_po_with_untranslated_strings(filename)

        poFile = POFile(filename)
        poFile._remove_untranslated_strings()

        po = polib.pofile(filename)
        self.assertEquals(1, len(po))
示例#4
0
    def test_add_msgctxt_to_duplicates(self):
        tmpfile = tempfile.NamedTemporaryFile()
        filename = tmpfile.name + ".po"
        self._create_po_with_duplicated_strings(filename)

        poFile = POFile(filename)
        poFile.add_msgctxt_to_duplicates()

        rslt = self._does_pofile_contains_duplicated_strings(filename)
        self.assertEquals(False, rslt)
示例#5
0
    def test_add_msgctxt_to_duplicates(self):
        tmpfile = tempfile.NamedTemporaryFile()
        filename = tmpfile.name + ".po"
        self._create_po_with_duplicated_strings(filename)

        poFile = POFile(filename)
        pofile = polib.POFile()
        poFile.add_msgctxt_to_duplicates()

        rslt = self._does_pofile_contains_duplicated_strings(filename)
        self.assertEquals(False, rslt)
示例#6
0
    def test_unescape_html(self):
        tmpfile = tempfile.NamedTemporaryFile()
        filename = tmpfile.name + ".po"

        self._create_po_with_html(filename)
        poFile = POFile(filename)
        poFile._unescape_html()

        po = polib.pofile(filename)
        self.assertEquals("use the <li> to begin each list item", po[0].msgid)

        self.assertEquals("\"Hi\"", po[1].msgstr)
    def test_add_comment_to_all_entries(self):
        tmpfile = tempfile.NamedTemporaryFile()
        f = open(tmpfile.name, 'w')
        f.write(self.minipo.encode('utf-8'))
        f.close()

        pofile = POFile(tmpfile.name)
        pofile.add_comment_to_all_entries(u'Comment test')

        input_po = polib.pofile(tmpfile.name)

        for entry in input_po:
            assert entry.tcomment == u'Comment test\nPlease remember to do something'
示例#8
0
    def test_add_comment_to_all_entries(self):
        tmpfile = tempfile.NamedTemporaryFile()
        f = open(tmpfile.name, 'w')
        f.write(self.minipo.encode('utf-8'))
        f.close()

        pofile = POFile(tmpfile.name)
        pofile.add_comment_to_all_entries(u'Comment test')

        input_po = polib.pofile(tmpfile.name)

        for entry in input_po:
            assert entry.tcomment == u'Comment test\nPlease remember to do something'
示例#9
0
def get_words(potext, po_directory):
    full_filename = os.path.join(po_directory, potext)
    words = POFile(full_filename).get_statistics()
    if words == 0:
        print("Skipping empty translation memory: " + potext)
        return None

    return words
 def test_calculate_localized_string_checksum(self):
     pofile = POFile(self.minipo)
     checksum = hashlib.new('sha1')
     pofile.calculate_localized_string_checksum(checksum)
     self.assertEquals(u'edf879d0199103cc09cc464deebdfd3e98613e4b', 
                 checksum.hexdigest())
 def test_get_statistics(self):
     pofile = POFile(self.minipo)
     assert pofile.get_statistics() == 5
示例#12
0
 def test_calculate_localized_string_checksum(self):
     pofile = POFile(self.minipo)
     checksum = hashlib.new('sha1')
     pofile.calculate_localized_string_checksum(checksum)
     self.assertEquals(u'edf879d0199103cc09cc464deebdfd3e98613e4b',
                 checksum.hexdigest())
示例#13
0
 def test_get_statistics(self):
     pofile = POFile(self.minipo)
     assert pofile.get_statistics() == 5