Exemplo n.º 1
0
 def test_get_comment_both(self):
     index = IndexCreator('.')
     entry = polib.POEntry()
     entry.comment = 'comment'
     entry.tcomment = 'tcomment'
     comment = index._get_comment(entry)
     self.assertEquals(comment, 'tcomment\r\ncomment')
Exemplo n.º 2
0
def main():
    """Create a Whoosh index for a PO file.

    Given a PO file, enumerates all the strings, and creates a Whoosh index to
    be able to search later.
    """
    print("Create Whoosh index from a PO file")
    print("Use --help for assistance")

    start_time = datetime.datetime.now()

    try:
        locale.setlocale(locale.LC_ALL, '')
    except Exception as detail:
        print("Exception: " + str(detail))

    po_directory, debug_keyword, projects_names = read_parameters()
    indexCreator = IndexCreator(po_directory, debug_keyword, projects_names)
    indexCreator.create()
    indexCreator.process_projects()

    ctx = {
        'date': datetime.date.today().strftime("%d/%m/%Y"),
        'projects': str(indexCreator.projects),
        'words': locale.format_string("%d", indexCreator.words, grouping=True),
    }
    write_index_json(ctx)

    print(
        "Time used to create the index: {0} ".format(datetime.datetime.now() -
                                                     start_time))
    def _create_index(self):
        '''Creates an index in RAM with the entries from data_set array'''
        self.index = IndexCreator('')
        index = self.index.create(True)

        for idx in range(0, len(self.data_set), self.FIELDS):
            self.index.write_entry(source=self.data_set[idx + 0],
                                   target=self.data_set[idx + 1],
                                   comment=u'',
                                   context=u'',
                                   project=self.data_set[idx + 2],
                                   softcatala=self.data_set[idx + 3])

        self.index.writer.commit()
        return index
    def test_process_project_plural(self):

        tmpfile = self._dump_po_to_file(self.minipo_plural)

        index = IndexCreator('.')
        index.writer = IndexWriterMock()
        index._process_file('test_project', tmpfile.name, False, set())
        stored = index.writer.store
        self.assertEquals(stored[0]['source'], u'Delete this photo from camera?')
        self.assertEquals(stored[0]['target'], u'Voleu suprimir aquesta fotografia de la càmera?')

        self.assertEquals(stored[1]['source'], u'Delete these %d photos from camera?')
        self.assertEquals(stored[1]['target'], u'Voleu suprimir aquestes %d fotografies de la càmera?')

        self.assertEquals(index.sentences, 2)
        self.assertEquals(index.sentences_indexed, 2)
    def test_process_project(self):

        tmpfile = self._dump_po_to_file(self.minipo)

        index = IndexCreator('.')
        index.writer = IndexWriterMock()
        index._process_file('test_project', tmpfile.name, False, set())
        stored = index.writer.store

        self.assertEquals(stored[0]['source'], u'Power off the selected virtual machines')
        self.assertEquals(stored[0]['target'], u'Apaga les màquines virtuals seleccionades')
        self.assertEquals(stored[0]['context'], 'Context')
        self.assertEquals(stored[0]['comment'], 'Please remember to do something\r\n')
        self.assertEquals(stored[0]['softcatala'], False)
        self.assertEquals(stored[0]['project'], 'test_project')
        self.assertEquals(index.words, 5)
        self.assertEquals(index.sentences, 1)
        self.assertEquals(index.sentences_indexed, 1)
def main():
    """Create a Whoosh index for a PO file.

    Given a PO file, enumerates all the strings, and creates a Whoosh index to
    be able to search later.
    """
    print("Create Whoosh index from a PO file")
    print("Use --help for assistance")

    start_time = datetime.datetime.now()

    try:
        locale.setlocale(locale.LC_ALL, '')
    except Exception as detail:
        print("Exception: " + str(detail))

    po_directory, debug_keyword, projects_names = read_parameters()
    indexCreator = IndexCreator(po_directory, debug_keyword, projects_names)
    indexCreator.create()
    indexCreator.process_projects()

    ctx = {
        'date': datetime.date.today().strftime("%d/%m/%Y"),
        'projects': str(indexCreator.projects),
        'words': locale.format_string("%d", indexCreator.words, grouping=True),
    }
    process_template("web/templates/statistics.mustache", "statistics.html",
                     ctx)

    ctx = {
        # This is the list of projects to display for the user to select.
        'options': sorted(indexCreator.options, key=lambda x: x.lower()),
    }
    process_template("web/templates/select-projects.mustache",
                     "select-projects.html", ctx)

    print(
        "Time used to create the index: {0} ".format(datetime.datetime.now() -
                                                     start_time))