Translate¶
Experimental module with the Translator class, which translates texts using the Google
Translate API (V2 and V3).
translate
¶
Experimental module to automate translations.
Classes:
| Name | Description |
|---|---|
Translator |
Class Translator is used for translation of strings based on the Google Translate API. |
Translator
¶
Translator(
api_key: str,
project_key: str = "",
domain: str = "",
logger: Logger = default_logger,
)
Class Translator is used for translation of strings based on the Google Translate API.
The class supports V2 and V3 translation APIs.
Initialize the Translate objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
The Google Translate API key. |
required |
project_key
|
str
|
The Google project. Defaults to "". |
''
|
domain
|
str
|
The domain. Defaults to "". |
''
|
logger
|
Logger
|
The logging object to log all messages. Defaults to default_logger. |
default_logger
|
Methods:
| Name | Description |
|---|---|
config |
Return the configuration parameters. |
translate |
Translate a string from one language to another using the Google Translate V2 API. |
translate_v3 |
Translate a string from one language to another using the Google Translate V3 API. |
Source code in packages/pyxecm/src/pyxecm_customizer/translate.py
config
¶
Return the configuration parameters.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The configuration parameters. |
translate
¶
Translate a string from one language to another using the Google Translate V2 API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_language
|
str
|
The source language. |
required |
target_language
|
str
|
The target language. |
required |
text
|
str
|
The string to translate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The translated string, or None if the request failed. |
Source code in packages/pyxecm/src/pyxecm_customizer/translate.py
translate_v3
¶
Translate a string from one language to another using the Google Translate V3 API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_language
|
str
|
The source language. |
required |
target_language
|
str
|
The destination language. |
required |
text
|
str
|
The string to translate. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The translated string, or None if the request failed. |