py-googletrans icon indicating copy to clipboard operation
py-googletrans copied to clipboard

Skip translation of specific fields

Open 510208 opened this issue 5 months ago • 1 comments

Googletrans version:

  • [x] 4.0.0rc1
  • [ ] 3.1.0a0
  • [ ] 3.0.0
  • [ ] 2.x

I'm submitting a ...

  • [ ] bug report
  • [x] feature request

Current behavior:

I am trying translate some text from English to Chinese(Tradional), below is my code:

def translate(text, dest='zh-tw'):
    if not text:
        return text  # 返回原文本如果是 None 或空字符串
    translator = Translator()
    result = translator.translate(text, dest).text
    print(f"Translated '{text}' to '{result}'")
    return result

I tried translate a text that contained a Placeholder like this:

%username% joined the server

and it responsed this text:

___%用戶名%__加入服務器

(If you want to know why the placeholder have some underline with the placeholder? Because I find this post on StackOverflow: How to tell Googletrans to ignore certain parts?)

Expected behavior:

It won't translate placeholder, like below:

%username%加入服務器

Steps to reproduce:

Below is my code, but I think it won't help... Translator.py: https://gist.github.com/510208/a60f2752872eabe11e8552e94d278e45 Checkformat.py: https://gist.github.com/510208/8b07f6a939bb8fa970cefdc9e86e8077

All right, the annotation is Chinese, maybe you need translate it or ignore it.

Related code:

510208 avatar Sep 12 '24 13:09 510208