Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip translation of specific fields #415

Open
2 of 6 tasks
510208 opened this issue Sep 12, 2024 · 1 comment
Open
2 of 6 tasks

Skip translation of specific fields #415

510208 opened this issue Sep 12, 2024 · 1 comment

Comments

@510208
Copy link

510208 commented Sep 12, 2024

Googletrans version:

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

I'm submitting a ...

  • bug report
  • 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:

@Haeherfeder
Copy link

tried the other comment? replace it with 1 before translating, and replace it back later. or just look for the ___% and the %after that, and replace it back with the content you wanted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants