How to override few translation?

I want to manually override few translations (some paragraphs in which grammar needs to be corrected manually) in translated language.

What’s the procedure ?

Also is there any online documentation available to refer ?

Please share some snippet if override is possible.

There’s not currently any functionality to do custom translations.

1 Like

Thank you so much don’t know how to solve now.

What type of custom translations do you want? Single words or large sections? With either it would probably be straightforward to do the replacement from Python or a shell script before passing to Argos Translate.

It’s sentence consist of around 15 words. Can you share any example

Here you go!

import argostranslate
from argostranslate import translate

text_to_translate = "Hello world. The previous sentence is a custom translation. Hello world."

def translate(s):
    from_lang_code = 'en'
    to_lang_code = 'es'
    from_lang = list(filter(lambda x: x.code == from_lang_code, argostranslate.translate.get_installed_languages()))[0]
    to_lang = list(filter(lambda x: x.code == to_lang_code, argostranslate.translate.get_installed_languages()))[0]
    translation = from_lang.get_translation(to_lang)
    return translation.translate(s)

def translate_custom(s, custom_translations):
    mappings = list(custom_translations.items())
    if len(mappings) == 0:
        return translate(s)
    mapping = mappings[0]
    i = s.find(mapping[0])
    if i < 0:
        return translate_custom(s, dict(mappings[1:]))
    return s[:i] + mapping[1] + translate_custom(s[i + len(mapping[0]):], custom_translations)

custom_translations = {
    'Hello world.': 'Hola Mars.'

print(translate_custom(text_to_translate, custom_translations))