API Reference¶
Welcome to the API reference for EsTranslator. This section provides detailed information about the classes, methods, and attributes available in the EsTranslator library.
es_translator.EsTranslator ¶
es_translator.EsTranslator(options)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options | Dict[str, Any] | A dictionary of options needed to set up the translator. | required |
Source code in es_translator/es_translator.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
no_progressbar property
¶
no_progressbar: bool
Check if the progressbar option is set to False.
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if the progressbar option is False, else False. |
search_source property
¶
search_source: List[str]
Gets the list of fields to use in the search.
Returns:
Type | Description |
---|---|
List[str] | List[str]: list of fields to use in the search. |
stdout_loglevel property
¶
stdout_loglevel: int
Gets the log level of stdout.
Returns:
Name | Type | Description |
---|---|---|
int | int | The log level of stdout. |
configure_search ¶
configure_search()
Configures the search object.
Returns:
Name | Type | Description |
---|---|---|
Search | Search | A configured search object. |
Source code in es_translator/es_translator.py
120 121 122 123 124 125 126 127 128 129 |
|
create_translation_queue ¶
create_translation_queue()
Creates a queue that can translate documents in parallel.
Returns:
Name | Type | Description |
---|---|---|
JoinableQueue | JoinableQueue | A queue for parallel document translation. |
Source code in es_translator/es_translator.py
143 144 145 146 147 148 149 |
|
init_interpreter ¶
init_interpreter()
Initializes the interpreter.
Returns:
Name | Type | Description |
---|---|---|
Any | Any | The initialized interpreter. |
Source code in es_translator/es_translator.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
instantiate_interpreter ¶
instantiate_interpreter()
Instantiates the interpreter.
Returns:
Name | Type | Description |
---|---|---|
Any | Any | An instance of the interpreter. |
Source code in es_translator/es_translator.py
109 110 111 112 113 114 115 116 117 118 |
|
print_done ¶
print_done(string)
Prints a string and yields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string | str | The string to be printed. | required |
Returns:
Name | Type | Description |
---|---|---|
ContextManager | ContextManager | A context manager. |
Source code in es_translator/es_translator.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
|
print_flush ¶
print_flush(string)
Prints and flushes a string to stdout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string | str | The string to be printed. | required |
Source code in es_translator/es_translator.py
255 256 257 258 259 260 261 262 |
|
process_document ¶
process_document(translation_queue, hit, progress, task, shared_fatal_error)
Processes a document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translation_queue | JoinableQueue | A queue for parallel document translation. | required |
hit | Any | The document to be translated. | required |
index | int | The index of the document. | required |
progress | Progress | A progress object. | required |
task | Any | The current task. | required |
shared_fatal_error | Manager | A shared manager for fatal errors. | required |
Source code in es_translator/es_translator.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
search ¶
search()
Executes a search query.
Returns:
Name | Type | Description |
---|---|---|
Search | Search | The search result. |
Source code in es_translator/es_translator.py
227 228 229 230 231 232 233 234 235 236 237 |
|
start ¶
start()
Starts or plans the translation process.
Source code in es_translator/es_translator.py
57 58 59 60 61 62 |
|
start_later ¶
start_later()
Plan the translation process.
Source code in es_translator/es_translator.py
76 77 78 79 80 81 82 83 84 85 |
|
start_now ¶
start_now()
Starts the translation process.
Source code in es_translator/es_translator.py
64 65 66 67 68 69 70 71 72 73 74 |
|
translate_documents_in_pool ¶
translate_documents_in_pool(search, translation_queue, shared_fatal_error, total)
Translates documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search | Search | A search object. | required |
translation_queue | JoinableQueue | A queue for parallel document translation. | required |
shared_fatal_error | Manager | A shared manager for fatal errors. | required |
total | int | The total number of documents. | required |
Source code in es_translator/es_translator.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
with_shared_fatal_error ¶
with_shared_fatal_error()
Creates a context manager for managing shared fatal errors.
Returns:
Name | Type | Description |
---|---|---|
ContextManager | ContextManager | A context manager. |
Source code in es_translator/es_translator.py
151 152 153 154 155 156 157 158 159 |
|
es_translator.interpreters.Argos ¶
es_translator.interpreters.Argos(source=None, target=None, intermediary=None, pack_dir=None)
Bases: AbstractInterpreter
Argos is a class that extends the AbstractInterpreter.
This class is responsible for handling translation tasks, specifically using the Argos interpreter.
Attributes:
Name | Type | Description |
---|---|---|
name | str | The name of the interpreter. |
The function also checks if the necessary language pair is available, and downloads it if necessary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source | str | The source language code. | None |
target | str | The target language code. | None |
intermediary | str | The intermediary language code. Defaults to None. | None |
pack_dir | str | The directory of language packs. This option will be ignored. Defaults to None. | None |
Raises:
Type | Description |
---|---|
Exception | If the necessary language pair is not available and cannot be downloaded. |
Source code in es_translator/interpreters/argos/argos.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
is_pair_available property
¶
is_pair_available
Checks if the necessary language pair is available in the installed packages.
Returns:
Name | Type | Description |
---|---|---|
bool | True if the language pair is available, False otherwise. |
local_languages property
¶
local_languages
Gets the codes for the installed languages.
This method retrieves the installed languages and returns their codes as a list. If an AttributeError is encountered, it returns an empty list.
Returns:
Type | Description |
---|---|
list of str: The codes for the installed languages. |
translation property
¶
translation
Returns a Translation object for the source and target languages.
Raises:
Type | Description |
---|---|
Exception | If either the source or target language is not installed. |
Returns:
Name | Type | Description |
---|---|---|
Translation | The Translation object for the source and target languages. |
download_and_install_package ¶
download_and_install_package(package)
Downloads and installs a language package.
This method locks the download using a file lock based on the package's source and target language codes. If the package is not installed, it is downloaded and installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package | Package | The package to download and install. | required |
Raises:
Type | Description |
---|---|
Timeout | If a lock on the download path cannot be acquired within the timeout duration. |
Source code in es_translator/interpreters/argos/argos.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
download_necessary_languages ¶
download_necessary_languages()
Downloads necessary language packages if they are not installed already.
This method performs the following steps: 1. Updates the package index. 2. Finds the necessary package. 3. Downloads and installs the package.
Raises:
Type | Description |
---|---|
ArgosPairNotAvailable | If the necessary language package could not be found. |
Timeout | If a lock on the download path cannot be acquired within the timeout duration. |
Source code in es_translator/interpreters/argos/argos.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
find_necessary_package ¶
find_necessary_package()
Finds the necessary language package.
This method loops over the available packages to find the necessary package based on the source and target language codes. If the package cannot be found, it raises an ArgosPairNotAvailable exception.
Returns:
Name | Type | Description |
---|---|---|
Package | The necessary language package. |
Raises:
Type | Description |
---|---|
ArgosPairNotAvailable | If the necessary language package could not be found. |
Source code in es_translator/interpreters/argos/argos.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
is_package_installed ¶
is_package_installed(package)
Checks if a package is installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package | Package | The package to check. | required |
Returns:
Name | Type | Description |
---|---|---|
bool | True if the package is installed, False otherwise. |
Source code in es_translator/interpreters/argos/argos.py
126 127 128 129 130 131 132 133 134 135 136 |
|
translate ¶
translate(text_input)
Translates the input text from the source language to the target language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text_input | str | The input text in the source language. | required |
Returns:
Name | Type | Description |
---|---|---|
str | The translated text in the target language. |
Source code in es_translator/interpreters/argos/argos.py
204 205 206 207 208 209 210 211 212 213 214 |
|
update_package_index ¶
update_package_index()
Updates the package index.
Source code in es_translator/interpreters/argos/argos.py
102 103 104 105 106 |
|