mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-16 11:46:33 +08:00
There is some peculiar behaviour with Google Translate API (translation provider) right now that requires this change.
### Extra context:
For each translation provider, we can make an API call to get the language code (locale) of a piece of text. This can be things like "en", "pt", "zh", "pt-PT", "zh-CN".
We use the result here to determine if the user is able to translate the post or not. If the user is in the same locale as the post, we do not allow them to translate since it is already in a readable language.
For some translation providers, we take this language code and tell the API "please translate this content from pt-PT to en". For some other providers, we can just do "please translate this content to en".
### This fix
Google Translate API is returning "bn-Latn" for some texts. However,
1. they do not support translation from "bn-Latn" to "en",
2. they do support translation from "bn" to "en",
3. same piece of text can be directly translated to "en" without supplying the source locale ("bn-Latn") 🤯
This fix does two things specific to the Google provider:
- Re-check if an unsupported language is supported, by removing the region part of the locale
- Send content for translation without indicating the source language
|
||
|---|---|---|
| .. | ||
| discourse_ai | ||
| problem_check | ||
| amazon_spec.rb | ||
| base_spec.rb | ||
| discourse_ai_spec.rb | ||
| google_spec.rb | ||
| libre_translate_spec.rb | ||
| microsoft_spec.rb | ||
| yandex_spec.rb | ||