Example #1
0
def convert_stores(input_store, template_store, tm=None, min_similarity=75, fuzzymatching=True, **kwargs):
    """Actual conversion function, works on stores not files, returns
    a properly initialized pretranslated output store, with structure
    based on input_store, metadata based on template_store, migrates
    old translations from template_store and pretranslating from tm"""

    #prepare for merging
    output_store = type(input_store)()
    #create fuzzy matchers to be used by pretranslate.pretranslate_unit
    matchers = []
    _prepare_merge(input_store, output_store, template_store)
    if fuzzymatching:
        if template_store:
            matcher = match.matcher(template_store, max_candidates=1, min_similarity=min_similarity, max_length=3000, usefuzzy=True)
            matcher.addpercentage = False
            matchers.append(matcher)
        if tm:
            matcher = pretranslate.memory(tm, max_candidates=1, min_similarity=min_similarity, max_length=1000)
            matcher.addpercentage = False
            matchers.append(matcher)

    #initialize store
    _store_pre_merge(input_store, output_store, template_store)

    # Do matching
    for input_unit in input_store.units:
        if input_unit.istranslatable():
            input_unit = pretranslate.pretranslate_unit(input_unit, template_store, matchers, mark_reused=True)
            _unit_post_merge(input_unit, input_store, output_store, template_store)
            output_store.addunit(input_unit)

    #finalize store
    _store_post_merge(input_store, output_store, template_store)

    return output_store
Example #2
0
def convert_stores(input_store,
                   template_store,
                   temp_store=None,
                   tm=None,
                   min_similarity=75,
                   fuzzymatching=True,
                   **kwargs):
    """Actual conversion function, works on stores not files, returns
    a properly initialized pretranslated output store, with structure
    based on input_store, metadata based on template_store, migrates
    old translations from template_store and pretranslating from TM.
    """
    if temp_store is None:
        temp_store = input_store

    # Create fuzzy matchers to be used by pretranslate.pretranslate_unit
    matchers = []

    _prepare_merge(input_store, temp_store, template_store)
    if fuzzymatching:
        if template_store:
            matcher = match.matcher(
                template_store,
                max_candidates=1,
                min_similarity=min_similarity,
                max_length=3000,
                usefuzzy=True,
            )
            matcher.addpercentage = False
            matchers.append(matcher)
        if tm:
            matcher = pretranslate.memory(tm,
                                          max_candidates=1,
                                          min_similarity=min_similarity,
                                          max_length=1000)
            matcher.addpercentage = False
            matchers.append(matcher)

    # initialize store
    _store_pre_merge(input_store, temp_store, template_store)

    # Do matching
    for input_unit in temp_store.units:
        if input_unit.istranslatable():
            input_unit = pretranslate.pretranslate_unit(
                input_unit,
                template_store,
                matchers,
                mark_reused=True,
                merge_on=input_store.merge_on,
            )
            _unit_post_merge(input_unit, input_store, temp_store,
                             template_store)

    # finalize store
    _store_post_merge(input_store, temp_store, template_store)

    return temp_store
Example #3
0
def convert_stores(input_store, template_store, temp_store=None, tm=None, min_similarity=75, fuzzymatching=True, **kwargs):
    """Actual conversion function, works on stores not files, returns
    a properly initialized pretranslated output store, with structure
    based on input_store, metadata based on template_store, migrates
    old translations from template_store and pretranslating from tm"""

    if temp_store is None:
        temp_store = input_store

    #create fuzzy matchers to be used by pretranslate.pretranslate_unit
    matchers = []
    _prepare_merge(input_store, temp_store, template_store)
    if fuzzymatching:
        if template_store:
            matcher = match.matcher(template_store, max_candidates=1, min_similarity=min_similarity, max_length=3000, usefuzzy=True)
            matcher.addpercentage = False
            matchers.append(matcher)
        if tm:
            matcher = pretranslate.memory(tm, max_candidates=1, min_similarity=min_similarity, max_length=1000)
            matcher.addpercentage = False
            matchers.append(matcher)

    #initialize store
    _store_pre_merge(input_store, temp_store, template_store)

    # Do matching
    match_locations = isinstance(input_store, po.pofile) and input_store.parseheader().get('X-Accelerator-Marker') in ('&', '~')
    for input_unit in temp_store.units:
        if input_unit.istranslatable():
            input_unit = pretranslate.pretranslate_unit(input_unit, template_store, matchers, mark_reused=True, match_locations=match_locations)
            _unit_post_merge(input_unit, input_store, temp_store, template_store)

    #finalize store
    _store_post_merge(input_store, temp_store, template_store)

    return temp_store