-
Notifications
You must be signed in to change notification settings - Fork 10
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
Unable to translate japanese #15
Comments
Hi. Is it reproduce with |
Hey, thanks for the quick reply, Yes the error is the same with translateBatch
result: [ '縺 薙 s 縺 縺.' ] |
As i see, a google API return this response: If google service can't translate this, then we can't fix it unfortunately. If you need, you can extend the class MyGoogleTranslator extends GoogleTranslator {
public translateBatch = async(texts: string[], from: string, to: string) => {
return texts.length === 1 ? [await this.translate(texts[0], from, to)] : super.translateBatch(texts, from, to);
}
} Or always call |
Hmmm it is translating for me on https://translate.google.com/ |
Hmmm, you know, i tried translate "こんにちは" and it's successfully translate for me. What environment you are use? Is it node? Maybe google are return wrong result for non-browser environments? |
I am using node. The translator itself is translating it properly, like described in the first post |
|
Ok, the info really helped, did not know 2 different api's were used. I did some digging and i found the following (not sure how helpful it really is) ssut/py-googletrans#268 (talking about some google api's) python example:
Result: |
@BtencateSphereon it's useful, thank you. I tried this code on https://translate.google.com/ var word = 'こんにちは';
var url = `https://translate.googleapis.com/translate_a/t?client=dict-chrome-ex&sl=ja&tl=en&q=${word}&q=${word}&q=${word}`;
await fetch(url).then(r=>r.json()) And i got result with translations. As i see, this API request is support batching, so probably we should use it. |
@BtencateSphereon i tried to use this API and it is not work for me at this time. You can checkout it with install const { GoogleTranslatorFree } = require('@translate-tools/core/translators/GoogleTranslator');
const translator = new GoogleTranslatorFree();
translator.translateBatch(['こんにちは'], 'ja', 'en').then((translate) => console.log(translate)) Maybe it will work with esm version? Try to run it as esm module: import { GoogleTranslatorFree } from '@translate-tools/core/esm/translators/GoogleTranslator';
const translator = new GoogleTranslatorFree();
translator.translateBatch(['こんにちは'], 'ja', 'en').then((translate) => console.log(translate)) When i run tests, it works fine, but it is not work from package |
Ok, i found solution. We should use header const { GoogleTranslator} = require('@translate-tools/core/translators/GoogleTranslator');
const translator = new GoogleTranslator({
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
},
});
translator.translateBatch(['こんにちは', 'こんにちは'], 'ja', 'en').then(console.log) |
I will update readme |
Very nice, thanks for the quick fix. I tested 0.2.4. and it works \o/. Will be closing this |
Hey,
i am noticing a difference in translation using the scheduler and directly using the translator
test string: こんにちは (hello in japanese)
scheduler:
`
const scheduler = new Scheduler(translator);
scheduler
.translate('こんにちは', 'ja', 'en')
.then((translate) => console.log(translate));
`
result: 縺 薙 s 縺 縺
translator:
`const translator = new GoogleTranslator();
translator
.translate('こんにちは', 'ja', 'en')
.then((translate) => console.log(translate))`
result: hello
is this something i am doing wrong or can fix?
Thanks in advance
The text was updated successfully, but these errors were encountered: