Translate and detect at same time using Google Translate API - google-translate

I want to use the google translate API to detect a language being typed and also get the translation but it seems this is not possible according to the docs here.
Does anyone know if this is possible? Or would I have to make two calls?
Thanks

Definitely you can detect and translate your contents at the same time. To be more specific, it will detect the source language automatically without specifying the source language by simply calling the Translation API method translate().

You can directly call the translate method without specifying the source language and only specify target language. Below is code snippet of code using
google-cloud-translate jar. It works perfect
Translate translate = getTranslationServiceClient();
// Translates some text into target language
Translation translation = translate.translate("Hello", TranslateOption.targetLanguage("hi"));

Related

Google Translate: UI translates but API fails

Just struggling with the following thing:
I have a lot of kind-of-comments-dirty-writing-manner comments. Comments came from India region, and there is a mix of languages (but not within the single comment). In addition there are samples with the transliteration, and I was wondering whether I can detect the language in this kind of mess.
But with Google Translate UI I found it deals with it.
As may be seen Google Translate UI detects language (probably correctly), suggests how the text should be written in the language detected, and finally translated it.
In contrast, Google Translate API does not give such a translation, but detects the language yet. Here's the response for the same input string:
translations {
translated_text: "Theek kiya"
detected_language_code: "hi"
}
So, I just wondering whether UI does additional stuff before it runs the translation, like spelling or whatever.
I do not see what did I missed with the API to make it finally translate the text.
Maybe someone faced the same problem and can help me?

adding a new language in google trans api python

I'm trying to add my country( senegal ) language(wo = wolof) into googletrans. I already build a list of words, so now I want to integrate them in googletrans python library.
Please.
I don't think it is possible. The Google Translate APIs are simply a client that send the requests to Google servers where the translation work is actually done. There is no way to add a new language to the API. (You can confirm this by looking at the (unofficial) API source code.)
Besides, you need more than just a word list to do a reasonable job of translating from one language to another. (Word mapping without any context tends to produce nonsense.)
Having said that ... if you believe that you can do reasonable translation based on simple word maps, then you don't need to use Google Translate APIs at all. You can use your word lists / maps directly in your Python program.

Translate API - different result from the web service

When using the translation API, I get a different translation (and worse) than if I use translate.google.com.
I am working on a project for a client, and the client was dissatisfied with the translation and noticed the difference.
Do these two service use different engines? I read that the API uses nmt-mode now, and that translate.google.com already uses the same engine.
Both set to translate from Norwegian to English.
Any more information that can clear this up?
Thanks!
The result differences between the translate.google.com and the Translation API calls are considered as an expected behavior that can be generated due to maintenance tasks and the logic used by the internal processes; However, the engines used for each service seems to be private information.
Based on this, it is normal to get some variances when using the API. I think you can use the model parameter option as an available workaround in case you want to specify which of the available models to use, as well as take a look on the Specifying a model official documentation to get detail information about this alternative.
It's almost about 3 years later and the problem still remains!
So I was trying to translate a dataset with the Google Translate API, but in the end it failed to translate some texts to the target language (in my case, Persian/Farsi). So I decided to check them to see if there's a pattern and maybe translate them using the web version of Google Translate.
As I was doing so, I figured that the web version actually could translate some of those untranslated texts, BUT not all. When trying to find a reason for such behaviour, I found out that most of them were names and not sentences. But as we know, names can easily be written with the target language characters as the translation. But why the API doesn't transform those names while the web version does? This photo will explain everything perhaps:
verified translation
As can be seen, some translations have a badge indicating that the translation has been verified, while some others don't.
So to recap, my guess is that maybe the API is set to only use verified translations, but as for the web version, even unverified translations are allowed since you can edit or report them.

Google Translate API Pricing and Language auto-detect Effeciency

I have the following three questions
I want to use Google's API to translate text. I know that Google charges separately for translation and detection. Google translate also supports translation two ways to translate
i) By specifying both source and target, as in
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world&q=My%20name%20is%20Jeff
ii) By specifying just the target, where the source us auto-detected,
like this https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&target=de&q=Hello%20world
My question is, if i call the API as in the second example, will I be charged for both detection and translation or just translation?
Is it more efficient when you specify both source and target than when you just the target, or, are there any downsides of using the second way above?
How many words should be sent to Google Translate API to detect a language reliably?
Thanks
I pretty much translate using the second approach most of the time (not informing to google the source language) and they only charge for the translation, not for the detection.
However, you must be aware of the fact that, in case your source text is of the same language as your target language, google will attempt to translate it anyways, and sometimes it leads to confused results, or at least a translation which was not necessary, since you already had the text in the desired language.

Defining new language based on C++

I would like to add a new language (called 'kiwi') into the Brackets code editor which is based on C++. It uses the exact same rules but has additional keywords.
I've already done the part of adding the additional keywords with separate syntax highlighting directly on the clike.js file but i don't really like directly modifying the def for C++
Can someone explain to me how I can achieve this? I don't really understand the difference between using def() and CodeMirror.defineMIME(). If this new language will take cpp/hpp input files, how will the editor switch from C++ -> kiwi?
Thanks in advance
Patching your local copy of the code, as you've done, might be perfectly fine for your needs. (And if you run from a Git copy of the source, it's easy to pull down updates without losing your local diffs).
If you want to do it a "cleaner" way, you can write a Brackets extension to define the new language - this way the change is easily shareable with others, and updating Brackets is even easier.
The way you'd do this roughly follows the Defining a new language docs:
Write an extension to package up your code that will define the new language (below)
The CM mode "clike" is already loaded, so you don't need to worry about that
Call CodeMirror.defineMIME() to set up a clike configuration with the right list of keywords - using a new mimetype name of your choosing. (Looking at the def() code in clike.js, I don't think the extra stuff it does is especially relevant for Brackets).
Call LanguageManager.defineLanguage() to tell Brackets about your new language mode (and what file extensions map to it, etc.). You should be able to mostly copy how the C++ mode is defined here - except with your new MIME name instead.
You should read CodeMirror documentation to find out about writing your modes.
But in short you can define your own type of clike language, by using CodeMirror.defineMIME().
You also asked what's the difference between def() and CodeMirror.defineMIME(). If you look at the code you can see that def() function is calling CodeMirror.defineMIME() at the end, so I believe it is just a more readable way of defining the type.
Also it seems that it's impossible to define more than one language on the same extension type (not 100% sure).

Resources