Skip to content

Conversation

@nattsw
Copy link
Contributor

@nattsw nattsw commented Mar 28, 2025

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

@nattsw nattsw merged commit dbd9af6 into main Mar 28, 2025
6 checks passed
@nattsw nattsw deleted the google-api-locale-dash branch March 28, 2025 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants