'Google translator is not working with Gujrati language written in english

# google-translate version 3.6.1

from os import environ
import os

from google.cloud import translate

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = r"/multilingual-bot.json"

project_id = 'multilingual-bot'

assert project_id
parent = f"projects/{project_id}"
client = translate.TranslationServiceClient()
client.get_supported_languages(parent=parent, display_language_code="en")

sample_text = "kevu chale che badhu"
target_language_code = "en"
lan_response = client.detect_language(parent=parent, content=sample_text)
response = client.translate_text(contents=[sample_text],source_language_code='gu',target_language_code=target_language_code,parent=parent)
for translation in response.translations:
    print(translation.translated_text)
print(lan_response)

when i pass "kevu chale che badhu" in sample_text the output remains same but if we change it in root language i.e "કેવુ ચલે છે બધુ" it will return correct output. I change the source language code to gu as well but nothing changed.



Solution 1:[1]

Currently, Google Cloud Translation API does not support the translation of any language written in the Latin Alphabet to the target language. The same has been raised as an issue in this issue tracker for hindi language. If you would like to have this feature for Gujarati language please raise a feature request using this link.However, we cannot provide an ETA at the moment but you can “STAR” the issue to receive automatic updates and give it traction by referring to this link.

Solution 2:[2]

The only known solution I can find, and I have successfully implmented (which handles Hindi, and other languages as well), is to transliterate the inputs.

I personally think it's a bad answer from Google that it isn't supported, because the target language that's returned from Latin-input characters (phonetically equivalent to the inputters desired speech), is the actual language. Thus "HI" is detected on Hindi, but the returned translation is just the same as the input. If Google can detect it's Hindi from the transliterated Latin-based characters, then why not just return the results?

Steps to work around:
1. translate through translate-api as normal.  Use the latin characters as the inputs.
2. receive the results from the the translate, and ignore the returned translation. (It will be the same as the input latin). Collect the targetLanguageDetected field, and save this.
3. call google's (deprecated but still supported) transliterate interface, with the input language (received from step 2) and the same original latin character inputs (URL is: https://inputtools.google.com/request?text=${srcMessage}&itc=${srclang}-t-i0-und&num=${numChoices}&cp=0&cs=1&ie=utf-8&oe=utf-8&app=demopage) - srcMessage is the original latin character text, srclang is the output from step 2, and numchoices is the number of "suggestions" that are generated from the input.
4. re run step 1, with the output from step 3 (the "HI" characters, or whatever alphabet is returned)

Google used to allow detection without a translate cost, but this isn't the case anymore.

In addition, Google's API is inconsistent in this behavior. For example if I type in Russian transliteration: "Privet", I get "Hello"

Solution 3:[3]

Hi google cloud console is made for english use you are not in admin fully its just what you manage example i tried shutting down my google could console it dident work i tried sudo and it worked the same way download the language package using sudo apt and install it using sudo do all work in sudo by sudo su if it does not work so that means that google does not want you to do so

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shipra Sarkar
Solution 2 G-Force
Solution 3 AlanTheGameEngine