Beispiel #1
0
def process_projects(src_directory, trg_directory):
    json = JsonBackend("projects.json")
    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)
    def add_comments(self):

        if not self.add_source:
            return

        findFiles = FindFiles()

        for filename in findFiles.find(self.temp_dir, "*.po"):
            relative = filename.replace(self.temp_dir, "")
            pofile = POFile()
            msg = "Translation source: {0} from project '{1}'".format(relative, self.project)
            pofile.add_comment_to_all_entries(filename, msg)
    def test_add_comment_to_all_entries(self):
        tmpfile = tempfile.NamedTemporaryFile()
        f = open(tmpfile.name, 'w')
        f.write(self.minipo)
        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'
    def add_comments(self):

        if not self.add_source:
            return

        findFiles = FindFiles()

        for filename in findFiles.find(self.temp_dir, '*.po'):
            relative = filename.replace(self.temp_dir, '')
            pofile = POFile(filename)
            msg = 'Translation source: {0} from project \'{1}\''.format(
                relative,
                self.project
            )
            pofile.add_comment_to_all_entries(msg)
Beispiel #5
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 add_comments(self):
        if not self.add_source:
            return

        findFiles = FindFiles()

        for filename in findFiles.find(self.temp_dir, '*.po'):
            relative = filename.replace(self.temp_dir, '')
            pofile = POFile(filename)

            if self.project_name.lower().strip() == self.name.lower().strip():
                msg = 'Source: {0} from project \'{1}\'' \
                    .format(relative, self.project_name)
            else:
                msg = 'Source: {0} from project \'{1} - {2}\'' \
                    .format(relative, self.project_name, self.name)

            pofile.add_comment_to_all_entries(msg)
            pofile.calculate_localized_string_checksum(self.checksum)
Beispiel #7
0
    def add_comments(self):
        if not self.add_source:
            return

        findFiles = FindFiles()

        for filename in findFiles.find(self.temp_dir, '*.po'):
            relative = filename.replace(self.temp_dir, '')
            pofile = POFile(filename)

            if self.project_name.lower().strip() == self.name.lower().strip():
                msg = 'Source: {0} from project \'{1}\'' \
                    .format(relative, self.project_name)
            else:
                msg = 'Source: {0} from project \'{1} - {2}\'' \
                    .format(relative, self.project_name, self.name)

            pofile.add_comment_to_all_entries(msg)
            pofile.calculate_localized_string_checksum(self.checksum)
 def test_get_statistics(self):
     pofile = POFile(self.minipo)
     assert pofile.get_statistics() == 5
 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())