discourse-translator/spec/services
Natalie Tay dbd9af6866
FIX: Skip locale region for Google Translate API (#263)
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
2025-03-28 16:21:03 +08:00
..
discourse_ai FEATURE: Better translation parsing via structured outputs (#257) 2025-03-21 15:48:05 -03:00
problem_check DEV: Cleanup terms (#232) 2025-02-27 17:40:56 +08:00
amazon_spec.rb UX: Show extra details in failure popup when translation fails (#262) 2025-03-28 13:24:32 +08:00
base_spec.rb FIX: Revert translating raw for translator providers as they strip newlines (#250) 2025-03-12 20:44:17 +08:00
discourse_ai_spec.rb FIX: Split content for translation before sending (#249) 2025-03-25 15:21:45 -03:00
google_spec.rb FIX: Skip locale region for Google Translate API (#263) 2025-03-28 16:21:03 +08:00
libre_translate_spec.rb FIX: Revert translating raw for translator providers as they strip newlines (#250) 2025-03-12 20:44:17 +08:00
microsoft_spec.rb UX: Show extra details in failure popup when translation fails (#262) 2025-03-28 13:24:32 +08:00
yandex_spec.rb DEV: Move translation custom fields into their own tables (#201) 2025-02-10 12:29:07 +08:00