This document describes how to use the Cloud Translation API to list supported languages.
Sending a supported languages request
You can discover the supported languages of this API by sending an HTTP request using a URL of the following format:
https://translation.googleapis.com/language/translate/v2/languages
Getting a list of supported languages
curl command
To get a list of all supported languages, make a GET request to the
https://translation.googleapis.com/language/translate/v2/languages endpoint.
The following shows an example of a GET request using
curl. The example uses the access token for a service account set up for the
project using the Google Cloud Platform Cloud SDK.
For instructions on installing the Cloud SDK,
setting up a project with a service account, and obtaining an access token,
see the Quickstart.
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
"https://translation.googleapis.com/language/translate/v2/languages"
If the request is successful, the server returns a 200 OK HTTP status code and
the response in JSON format:
{
"data": {
"languages": [
{
"language": "en"
},
{
"language": "fr"
},
...
{
"language": "zh-CN"
}
]
}
}
This query returns iso-639-1 language codes for supported languages. Some language codes also include a country code, like zh-CN or zh-TW. The list is sorted alphabetically by language code.
C#
Go
Java
Node.js
PHP
Python
Ruby
Listing supported languages in target language
curl command
Here is another example that returns the list of supported languages. The returned language names are written in a specified target language. The returned list is sorted alphabetically according to the target language.
To detect the language of some text, make a POST request and provide JSON
that identifies the target language in the request body. The following
shows an example of a POST request using curl.
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
--data "{
'target': 'zh-TW'
}" "https://translation.googleapis.com/language/translate/v2/languages"
If the request is successful, the server returns a 200 OK HTTP status code and
the response in JSON format:
{
"data": {
"languages": [
{
"language": "zh-CN",
"name": "中文(簡體)"
},
{
"language": "fr",
"name": "法文"
},
...
{
"language": "en",
"name": "英文"
}
]
}
}
In this case, the query returns the same language codes as above, along with
name strings that give the names of the languages written in the target
language, zh-TW.


