Use the Cloud Translation API to list the languages that are supported by the NMT model. To view the supported language pairs for AutoML Translation, see Language support for custom models.
Before you begin
Before you can start using the Cloud Translation API, you must have a project that has the Cloud Translation API enabled, and you must have the appropriate credentials. You can also install client libraries for common programming languages to help you make calls to the API. For more information, see the Setup page.
List supported languages
REST
To get a list of all supported languages, make a GET
request to the
https://translation.googleapis.com/v3/projects/project-number-or-id/locations/location/supportedLanguages
URL.
The following shows an example of a GET
request using
curl
and PowerShell. The example uses the access token for a service account
set up for the project using the Google Cloud Google Cloud CLI.
For instructions on installing the Google Cloud CLI,
setting up a project with a service account, and obtaining an access token,
see the Setup page.
Before using any of the request data, make the following replacements:
- PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
HTTP method and URL:
GET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/global/supportedLanguages
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "languages": [ "languageCode": "af", "supportSource": true, "supportTarget": true }, { "languageCode": "am", "supportSource": true, "supportTarget": true }, { "languageCode": "ar", "supportSource": true, "supportTarget": true }, .... { "languageCode": "zu", "supportSource": true, "supportTarget": true } ] }
The list is sorted alphabetically by language code. This query returns ISO-639 language codes for supported languages. Some language codes also include a country code, like zh-CN or zh-TW. For example:
{ "languageCode": "zh-TW", "supportSource": true, "supportTarget": true },
Go
Before trying this sample, follow the Go setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Go API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Java API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Node.js API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Python API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Cloud Translation reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Cloud Translation reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Cloud Translation reference documentation for Ruby.
List supported languages with target language name
REST
Here is another example that returns the list of supported languages with the returned language names written in the specified target language. The returned list is sorted alphabetically according to the target language.
Before using any of the request data, make the following replacements:
- PROJECT_NUMBER_OR_ID: the numeric or alphanumeric ID of your Google Cloud project
HTTP method and URL:
GET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/global/supportedLanguages?display_language_code=sq
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "languages": [{ "languageCode": "af", "displayName": "Afrikanisht", "supportSource": true, "supportTarget": true }, { "languageCode": "am", "displayName": "Amarikisht", "supportSource": true, "supportTarget": true }, { "languageCode": "en", "displayName": "Anglisht", "supportSource": true, "supportTarget": true }, ...{ "languageCode": "zu", "displayName": "Zulu", "supportSource": true, "supportTarget": true } ] }
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. In this example, the language is Albanian (sq).
Go
Before trying this sample, follow the Go setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Go API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Java API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Node.js API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Before trying this sample, follow the Python setup instructions in the Cloud Translation quickstart using client libraries. For more information, see the Cloud Translation Python API reference documentation.
To authenticate to Cloud Translation, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Cloud Translation reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Cloud Translation reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Cloud Translation reference documentation for Ruby.
Additional resources
- For help on resolving common issues or errors, see the Troubleshooting page.