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

[Bug]: Google doesn't give the correct translation #163

Open
2 tasks done
bropines opened this issue Oct 25, 2024 · 5 comments
Open
2 tasks done

[Bug]: Google doesn't give the correct translation #163

bropines opened this issue Oct 25, 2024 · 5 comments
Assignees

Comments

@bropines
Copy link

Debug Tips

  • I'm sure I've read this project's Issues of README.

What happened?

For some reason, in response to the request, only one part of the text (brackets) is received, and the second is lost

Original text: 従いまひゅ 宮司 ……

Translated text:
[bing] и Священник Храма......
[google] Итак, Маху Мияши ...
[yandex] Ошибка при переводе: Unsupported from_language[ja] in ['az', 'be', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'hy', 'it', 'lt', 'lv', 'mk', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv', 'tr', 'uk', 'zh'].
[alibaba] И следуй за Махи Мияджи...
 python .\test.py

Original text: (kudze sara) 従いまひゅ 宮司 ……

Translated text:
[bing] (кудзе сара) и г-н Миядзи......
[google] (Кудзе Сара)
[yandex] Ошибка при переводе: Unsupported from_language[ja] in ['az', 'be', 'bg', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'hy', 'it', 'lt', 'lv', 'mk', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv', 'tr', 'uk', 'zh'].
[alibaba] (Кудзе Сара)

APP Version

5.9.3 (default)

Python Version

3.10

Runtime Environment

Windows

Country/Region

Russia

Relevant log output

No response

Screenshots

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@bropines
Copy link
Author

And also, Yandex can translate Japanese, but apparently you haven’t updated this in the code

@UlionTse
Copy link
Owner

UlionTse commented Nov 13, 2024

@bropines Sorry for long time.

  1. About Google:
    Can you provide Google's wrong result and web correct result correspondingly?
# My judgment:
if translators's google result == google web result:
    return True

# Your judgment:
if translators's google result == My idea result:
    return True

Of course, Maybe this: #35
Second lost: Maybe your request is so fast that you could not recieve complete result. (Imagine a rendering of a web page)

  1. About Yandex:
    You are right, next version package will be updated. But you can do this temporarily:
import translators as ts

print(ts.translate_text(query_text='你好', translator='yandex'))
ts.server._yandex.language_map.update({'ja': ['ru']})  # add lang_pair you want
print(ts.translate_text(query_text='こんにちは', translator='yandex', from_language='ja', to_language='ru'))

@UlionTse
Copy link
Owner

Imagine typing a sentence in real time in a web page translation window. How many times does the request result refresh behind it? If the input generated a large number of translation requests queue in a short time, if I were a developer, I would design a sliding window such as 24ms, I only handle the latest request in the sliding window, so as to basically meet the effect of real-time translation of the web page.
As you asked, if your requests are too fast and multiple requests are planned into a sliding window, will the results be lost?

@bropines
Copy link
Author

That is, I make requests so quickly that the second part of the translation simply doesn’t load for me... Right?

And essentially I can just make the wait a little longer when receiving a transfer. I wish I knew how....

@bropines
Copy link
Author

I still remembered the problem. Here are my tests

import translators as ts

# Define the original texts to translate
original_text_1 = "し 、 従いまひゅ 宮司 様……"
original_text_2 = "(kudze sara) し 、 従いまひゅ 宮司 様……"

# List of translators to test
translators_to_test = ['google', 'bing', 'alibaba', 'yandex']

# Print a sample Yandex translation to ensure functionality
try:
    print(ts.translate_text(query_text='你好', translator='yandex'))
    ts.server._yandex.language_map.update({'ja': ['ru']})  # Add language pair
    print(ts.translate_text(query_text='こんにちは', translator='yandex', from_language='ja', to_language='ru'))
except Exception as e:
    print(f"Failed to update or test Yandex language map: {e}")

# Function to perform translations and collect results
def translate_texts(original_texts, translators):
    results = {}
    for text in original_texts:
        text_translations = {}
        for translator in translators:
            try:
                translated_text = ts.translate_text(text, translator=translator, from_language='auto', to_language='ru')
            except Exception as e:
                translated_text = f"Ошибка при переводе: {str(e)}"
            text_translations[translator] = translated_text
        results[text] = text_translations
    return results

# Translate the texts
results = translate_texts([original_text_1, original_text_2], translators_to_test)

# Format and print results
for original_text, translations in results.items():
    print(f"Original text: {original_text}\n")
    print("Translated text:")
    for translator, translated_text in translations.items():
        print(f"[{translator}] {translated_text}")
    print("\n")

Result:

Original text: し 、 従いまひゅ 宮司 様……

Translated text:
[google] Итак, Маху Мияши ...
[bing] и Священник Храма......
[alibaba] Es, ま ま ま Дворец...
[yandex] я последую за тобой, господь махью.……


Original text: (kudze sara) し 、 従いまひゅ 宮司 様……

Translated text:
[google] (Кудзе Сара)
[bing] (кудзе сара) и г-н Миядзи......
[alibaba] (Kudze sara) «Дворец»...
[yandex] (кудзе Сара) тогда я буду повиноваться главному жрецу махью.……

Screenshot from google
image

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