Reference documentation and code samples for the Cloud Translation API module Google::Cloud::Translate.
Methods
.configure
defself.configure()->::Google::Cloud::Config
Configure the google-cloud-translate library.
The following configuration parameters are supported:
credentials(type:String, Hash, Google::Auth::Credentials) -
The path to the keyfile as a String, the contents of the keyfile as a
Hash, or a Google::Auth::Credentials object.
lib_name(type:String) -
The library name as recorded in instrumentation and logging.
lib_version(type:String) -
The library version as recorded in instrumentation and logging.
interceptors(type:Array<GRPC::ClientInterceptor>) -
An array of interceptors that are run before calls are executed.
timeout(type:Numeric) -
Default timeout in seconds.
metadata(type:Hash{Symbol=>String}) -
Additional headers to be sent with the call.
retry_policy(type:Hash) -
The retry policy. The value is a hash with the following keys:
:initial_delay(type:Numeric) - The initial delay in seconds.
:max_delay(type:Numeric) - The max delay in seconds.
:multiplier(type:Numeric) - The incremental backoff multiplier.
:retry_codes(type:Array<String>) -
The error codes that should trigger a retry.
Yields
(::Google::Cloud.configure.translate)
Returns
(::Google::Cloud::Config) — The default configuration used by this library
Create a new client object for TranslationService.
By default, this returns an instance ofGoogle::Cloud::Translate::V3::TranslationService::Clientfor a gRPC client for version V3 of the API.
However, you can specify a different API version by passing it in theversionparameter. If the TranslationService service is
supported by that API version, and the corresponding gem is available, the
appropriate versioned client will be returned.
You can also specify a different transport by passing:restor:grpcin
thetransportparameter.
Raises an exception if the currently installed versioned client gem for the
given API version does not support the given transport of the TranslationService service.
You can determine whether the method will succeed by callingTranslate.translation_service_available?.
About TranslationService
Provides natural language translation operations.
Parameters
version(::String, ::Symbol)(defaults to: :v3)— The API version to connect to. Optional.
Defaults to:v3.
transport(:grpc, :rest)(defaults to: :grpc)— The transport to use. Defaults to:grpc.
Returns
(::Object) — A client object for the specified version.
Determines whether the TranslationService service is supported by the current client.
If true, you can retrieve a client object by callingTranslate.translation_service.
If false, that method will raise an exception. This could happen if the given
API version does not exist or does not support the TranslationService service,
or if the versioned client gem needs an update to support the TranslationService service.
Parameters
version(::String, ::Symbol)(defaults to: :v3)— The API version to connect to. Optional.
Defaults to:v3.
transport(:grpc, :rest)(defaults to: :grpc)— The transport to use. Defaults to:grpc.
Creates a new object for connecting to the legacy V2 version of the
Cloud Translation API.
Like other Cloud Platform services, Google Cloud Translation API supports authentication using a project ID
and OAuth 2.0 credentials. In addition, it supports authentication using a public API access key. (If both the
API key and the project and OAuth 2.0 credentials are provided, the API key will be used.) Instructions and
configuration options are covered in theAuthentication Guide.
Parameters
project_id(String)(defaults to: nil)— Project identifier for the Cloud Translation service you are connecting to. If not
present, the default project for the credentials is used.
credentials(String, Hash, Google::Auth::Credentials)(defaults to: nil)— The path to the keyfile as a String, the contents
of the keyfile as a Hash, or a Google::Auth::Credentials object.
key(String)(defaults to: nil)— a public API access key (not an OAuth 2.0 token)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Translation API - Module Google::Cloud::Translate (v3.7.2)\n\nVersion latestkeyboard_arrow_down\n\n- [3.7.2 (latest)](/ruby/docs/reference/google-cloud-translate/latest/Google-Cloud-Translate)\n- [3.7.1](/ruby/docs/reference/google-cloud-translate/3.7.1/Google-Cloud-Translate)\n- [3.6.1](/ruby/docs/reference/google-cloud-translate/3.6.1/Google-Cloud-Translate)\n- [3.5.0](/ruby/docs/reference/google-cloud-translate/3.5.0/Google-Cloud-Translate)\n- [3.4.1](/ruby/docs/reference/google-cloud-translate/3.4.1/Google-Cloud-Translate)\n- [3.3.0](/ruby/docs/reference/google-cloud-translate/3.3.0/Google-Cloud-Translate)\n- [3.2.3](/ruby/docs/reference/google-cloud-translate/3.2.3/Google-Cloud-Translate) \nReference documentation and code samples for the Cloud Translation API module Google::Cloud::Translate.\n\nMethods\n-------\n\n### .configure\n\n def self.configure() -\u003e ::Google::Cloud::Config\n\nConfigure the google-cloud-translate library.\n\nThe following configuration parameters are supported:\n\n- `credentials` (*type:* `String, Hash, Google::Auth::Credentials`) - The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object.\n- `lib_name` (*type:* `String`) - The library name as recorded in instrumentation and logging.\n- `lib_version` (*type:* `String`) - The library version as recorded in instrumentation and logging.\n- `interceptors` (*type:* `Array\u003cGRPC::ClientInterceptor\u003e`) - An array of interceptors that are run before calls are executed.\n- `timeout` (*type:* `Numeric`) - Default timeout in seconds.\n- `metadata` (*type:* `Hash{Symbol=\u003eString}`) - Additional headers to be sent with the call.\n- `retry_policy` (*type:* `Hash`) - The retry policy. The value is a hash with the following keys:\n - `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.\n - `:max_delay` (*type:* `Numeric`) - The max delay in seconds.\n - `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.\n- `:retry_codes` (*type:* `Array\u003cString\u003e`) - The error codes that should trigger a retry. \n**Yields**\n\n- (::Google::Cloud.configure.translate) \n**Returns**\n\n- (::Google::Cloud::Config) --- The default configuration used by this library\n\n### .translation_service\n\n def self.translation_service(version: :v3, transport: :grpc, &block) -\u003e ::Object\n\nCreate a new client object for TranslationService.\n\n\nBy default, this returns an instance of\n[Google::Cloud::Translate::V3::TranslationService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-translate-v3/latest/Google-Cloud-Translate-V3-TranslationService-Client)\nfor a gRPC client for version V3 of the API.\nHowever, you can specify a different API version by passing it in the\n`version` parameter. If the TranslationService service is\nsupported by that API version, and the corresponding gem is available, the\nappropriate versioned client will be returned.\nYou can also specify a different transport by passing `:rest` or `:grpc` in\nthe `transport` parameter.\n\n\u003cbr /\u003e\n\nRaises an exception if the currently installed versioned client gem for the\ngiven API version does not support the given transport of the TranslationService service.\nYou can determine whether the method will succeed by calling\n[Translate.translation_service_available?](/ruby/docs/reference/google-cloud-translate/latest/Google-Cloud-Translate#Google__Cloud__Translate_translation_service_available__class_ \"Google::Cloud::Translate.translation_service_available? (method)\").\n\n#### About TranslationService\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nProvides natural language translation operations. \n**Parameters**\n\n- **version** (::String, ::Symbol) *(defaults to: :v3)* --- The API version to connect to. Optional. Defaults to `:v3`.\n- **transport** (:grpc, :rest) *(defaults to: :grpc)* --- The transport to use. Defaults to `:grpc`. \n**Returns**\n\n- (::Object) --- A client object for the specified version.\n\n### .translation_service_available?\n\n def self.translation_service_available?(version: :v3, transport: :grpc) -\u003e boolean\n\nDetermines whether the TranslationService service is supported by the current client.\nIf true, you can retrieve a client object by calling [Translate.translation_service](/ruby/docs/reference/google-cloud-translate/latest/Google-Cloud-Translate#Google__Cloud__Translate_translation_service_class_ \"Google::Cloud::Translate.translation_service (method)\").\nIf false, that method will raise an exception. This could happen if the given\nAPI version does not exist or does not support the TranslationService service,\nor if the versioned client gem needs an update to support the TranslationService service. \n**Parameters**\n\n- **version** (::String, ::Symbol) *(defaults to: :v3)* --- The API version to connect to. Optional. Defaults to `:v3`.\n- **transport** (:grpc, :rest) *(defaults to: :grpc)* --- The transport to use. Defaults to `:grpc`. \n**Returns**\n\n- (boolean) --- Whether the service is available.\n\n### .translation_v2_service\n\n def self.translation_v2_service(project_id: nil, credentials: nil, key: nil, scope: nil, retries: nil, timeout: nil, endpoint: nil) -\u003e Google::Cloud::Translate::V2::Api\n\nCreates a new object for connecting to the legacy V2 version of the\nCloud Translation API.\n\n\n\u003cbr /\u003e\n\nLike other Cloud Platform services, Google Cloud Translation API supports authentication using a project ID\nand OAuth 2.0 credentials. In addition, it supports authentication using a public API access key. (If both the\nAPI key and the project and OAuth 2.0 credentials are provided, the API key will be used.) Instructions and\nconfiguration options are covered in the [Authentication Guide](./AUTHENTICATION \"Authentication Guide\"). \n**Parameters**\n\n- **project_id** (String) *(defaults to: nil)* --- Project identifier for the Cloud Translation service you are connecting to. If not present, the default project for the credentials is used.\n- **credentials** (String, Hash, Google::Auth::Credentials) *(defaults to: nil)* --- The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object.\n- **key** (String) *(defaults to: nil)* --- a public API access key (not an OAuth 2.0 token)\n- **scope** (String, Array\\\u003cString\\\u003e) *(defaults to: nil)* ---\n\n The OAuth 2.0 scopes controlling the set of resources and operations that\n the connection can access. See [Using OAuth 2.0 to Access Google\n APIs](https://developers.google.com/identity/protocols/OAuth2).\n\n The default scope is:\n - `https://www.googleapis.com/auth/cloud-platform`\n- **retries** (Integer) *(defaults to: nil)* --- Number of times to retry requests on server error. The default value is `3`. Optional.\n- **timeout** (Integer) *(defaults to: nil)* --- Default timeout to use in requests. Optional.\n- **endpoint** (String) *(defaults to: nil)* --- Override of the endpoint host name. Optional. If the param is nil, uses the default endpoint. \n**Returns**\n\n- (Google::Cloud::Translate::V2::Api)\n**Examples** \n\n```ruby\nrequire \"google/cloud/translate/v2\"\n\ntranslate = Google::Cloud::Translate::V2.new(\n version: :v2,\n project_id: \"my-todo-project\",\n credentials: \"/path/to/keyfile.json\"\n)\n\ntranslation = translate.translate \"Hello world!\", to: \"la\"\ntranslation.text #=\u003e \"Salve mundi!\"\n```\n\nUsing API Key. \n\n```ruby\nrequire \"google/cloud/translate/v2\"\n\ntranslate = Google::Cloud::Translate::V2.new(\n key: \"api-key-abc123XYZ789\"\n)\n\ntranslation = translate.translate \"Hello world!\", to: \"la\"\ntranslation.text #=\u003e \"Salve mundi!\"\n```\n\nUsing API Key from the environment variable. \n\n```ruby\nrequire \"google/cloud/translate/v2\"\n\nENV[\"TRANSLATE_KEY\"] = \"api-key-abc123XYZ789\"\n\ntranslate = Google::Cloud::Translate::V2.new\n\ntranslation = translate.translate \"Hello world!\", to: \"la\"\ntranslation.text #=\u003e \"Salve mundi!\"\n```\n\nConstants\n---------\n\n### VERSION\n\n**value:**\"3.7.2\""]]