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.
Core¶
es_translator.EsTranslator ¶
EsTranslator(options)
Orchestrates translation of Elasticsearch documents.
Manages the translation workflow including searching for documents, parallel translation using worker pools, and updating translated documents.
Attributes:
| Name | Type | Description |
|---|---|---|
url | Elasticsearch URL. | |
index | Index name to search and update. | |
source_language | Source language code. | |
target_language | Target language code. | |
intermediary_language | Optional intermediary language for indirect translation. | |
source_field | Field name containing source text. | |
target_field | Field name to store translated text. | |
query_string | Optional Elasticsearch query string. | |
data_dir | Directory for storing interpreter data. | |
scan_scroll | Scroll timeout for search. | |
dry_run | If True, skip saving translated documents. | |
force | Force re-translation of already translated documents. | |
pool_size | Number of parallel worker processes. | |
pool_timeout | Timeout for worker pool operations. | |
throttle | Throttle for rate limiting. | |
progressbar | Show progress bar during translation. | |
interpreter_name | Name of translation interpreter to use. | |
max_content_length | Maximum content length to translate (-1 for unlimited). | |
plan | If True, queue translations for later execution. | |
interpreter | Instantiated interpreter instance. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
options | dict[str, Any] | Dictionary of configuration options. | required |
Source code in es_translator/es_translator.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
no_progressbar property ¶
no_progressbar
Check if the progressbar option is set to False.
Returns:
| Name | Type | Description |
|---|---|---|
bool | bool | True if the progressbar option is False, else False. |
options property ¶
options
Get configuration options as a dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary containing all configuration options. |
search_source property ¶
search_source
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
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
176 177 178 179 180 181 182 183 184 185 | |
create_client ¶
create_client()
Create an Elasticsearch client instance.
Returns:
| Type | Description |
|---|---|
Elasticsearch | Configured Elasticsearch client. |
Source code in es_translator/es_translator.py
401 402 403 404 405 406 407 | |
create_translated_hit ¶
create_translated_hit(hit)
Create a TranslatedHit wrapper for a document hit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hit | ObjectBase | Document hit object. | required |
Returns:
| Type | Description |
|---|---|
TranslatedHit | TranslatedHit instance ready for translation. |
Source code in es_translator/es_translator.py
390 391 392 393 394 395 396 397 398 399 | |
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
198 199 200 201 202 203 204 | |
find_document ¶
find_document(params)
Find a document by ID and routing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params | dict[str, str] | Dictionary containing 'index', 'id', and optionally 'routing'. | required |
Returns:
| Type | Description |
|---|---|
Document | The found Document object. |
Source code in es_translator/es_translator.py
216 217 218 219 220 221 222 223 224 225 226 227 | |
init_interpreter ¶
init_interpreter()
Initializes the interpreter.
Returns:
| Name | Type | Description |
|---|---|---|
Any | Any | The initialized interpreter. |
Source code in es_translator/es_translator.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
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
165 166 167 168 169 170 171 172 173 174 | |
print_done ¶
print_done(string)
Print progress message and yield, showing done/error status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string | str | The status message to be printed. | required |
Returns:
| Type | Description |
|---|---|
None | Generator for wrapping operations with status output. |
Source code in es_translator/es_translator.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | |
print_flush ¶
print_flush(string)
Print and flush 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
344 345 346 347 348 349 350 351 | |
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
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
search ¶
search()
Executes a search query.
Returns:
| Name | Type | Description |
|---|---|---|
Search | Search | The search result. |
Source code in es_translator/es_translator.py
313 314 315 316 317 318 319 320 321 322 323 | |
start ¶
start()
Starts or plans the translation process.
Source code in es_translator/es_translator.py
102 103 104 105 106 107 | |
start_later ¶
start_later()
Queue translation tasks for later execution via Celery.
Source code in es_translator/es_translator.py
124 125 126 127 128 129 130 131 132 133 134 | |
start_now ¶
start_now()
Start the translation process immediately.
Source code in es_translator/es_translator.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
translate_document ¶
translate_document(hit)
Translate a single document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hit | ObjectBase | Document hit object to translate. | required |
Source code in es_translator/es_translator.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
translate_documents_direct ¶
translate_documents_direct(search, total)
Translate documents directly without multiprocessing.
Used when pool_size=1 for simpler execution and better GPU compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search | Search | A search object. | required |
total | int | The total number of documents. | required |
Source code in es_translator/es_translator.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
translate_documents_in_pool ¶
translate_documents_in_pool(
search, translation_queue, shared_fatal_error, total
)
Translates documents using multiprocessing pool.
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
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
with_shared_fatal_error ¶
with_shared_fatal_error()
Creates a context manager for managing shared fatal errors.
Returns:
| Type | Description |
|---|---|
None | Generator yielding a shared manager value. |
Source code in es_translator/es_translator.py
206 207 208 209 210 211 212 213 214 | |
Interpreters¶
EsTranslator supports multiple translation backends (interpreters). Each interpreter has its own strengths and supported language pairs.
Argos¶
Argos Translate is a neural machine translation library that provides high-quality translations using offline models.
es_translator.interpreters.Argos ¶
Argos(
source=None,
target=None,
intermediary=None,
pack_dir=None,
device=None,
)
Bases: AbstractInterpreter
Argos translation interpreter using argostranslate.
This class handles translation tasks using the Argos neural machine translation engine. Note that Argos does not support intermediary languages or custom package directories.
Attributes:
| Name | Type | Description |
|---|---|---|
name | Identifier for this interpreter ('ARGOS'). |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | Optional[str] | Source language code. | None |
target | Optional[str] | Target language code. | None |
intermediary | Optional[str] | Intermediary language code (not supported, will warn if provided). | None |
pack_dir | Optional[str] | Directory for language packs (not supported, will warn if provided). | None |
device | Optional[str] | Device for translation ('cpu', 'cuda', or 'auto'). Defaults to config value. | None |
Raises:
| Type | Description |
|---|---|
Exception | If the necessary language pair is not available. |
Source code in es_translator/interpreters/argos/argos.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
is_pair_available property ¶
is_pair_available
Check if the necessary language pair is available in installed packages.
Returns:
| Type | Description |
|---|---|
bool | True if the language pair is available, False otherwise. |
local_languages property ¶
local_languages
Get the codes for the installed languages.
Returns:
| Type | Description |
|---|---|
list[str] | List of installed language codes. Returns empty list if languages cannot be retrieved. |
translation property ¶
translation
Get Translation object for the source and target languages.
Returns:
| Type | Description |
|---|---|
Any | Translation object configured for source to target language. |
Raises:
| Type | Description |
|---|---|
IndexError | If either the source or target language is not installed. |
download_and_install_package ¶
download_and_install_package(package)
Download and install a language package.
Uses file locking to prevent concurrent downloads of the same package. Skips installation if the package is already installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package | Any | The package to download and install. | required |
Returns:
| Type | Description |
|---|---|
Optional[Any] | Installation result or None if package was already installed. |
Raises:
| Type | Description |
|---|---|
ArgosPackageDownloadLockTimeout | If lock cannot be acquired within timeout. |
Source code in es_translator/interpreters/argos/argos.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
download_necessary_languages ¶
download_necessary_languages()
Download necessary language packages if not installed.
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. |
ArgosPackageDownloadLockTimeout | If lock cannot be acquired within timeout. |
Source code in es_translator/interpreters/argos/argos.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | |
find_necessary_package ¶
find_necessary_package()
Find the necessary language package.
Searches available packages for one matching the source and target languages.
Returns:
| Type | Description |
|---|---|
Any | The necessary language package object. |
Raises:
| Type | Description |
|---|---|
ArgosPairNotAvailable | If the necessary language package could not be found. |
Source code in es_translator/interpreters/argos/argos.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | |
is_package_installed ¶
is_package_installed(package)
Check if a package is installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package | Any | The package to check. | required |
Returns:
| Type | Description |
|---|---|
bool | True if the package is installed, False otherwise. |
Source code in es_translator/interpreters/argos/argos.py
190 191 192 193 194 195 196 197 198 199 200 | |
translate ¶
translate(text_input)
Translate input text from source language to target language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text_input | str | The input text in the source language. | required |
Returns:
| Type | Description |
|---|---|
str | The translated text in the target language. |
Source code in es_translator/interpreters/argos/argos.py
265 266 267 268 269 270 271 272 273 274 275 276 | |
update_package_index ¶
update_package_index()
Update the Argos package index to fetch latest available packages.
Source code in es_translator/interpreters/argos/argos.py
168 169 170 171 | |
Apertium¶
Apertium is a rule-based machine translation platform that supports a wide variety of language pairs, especially for related languages.
es_translator.interpreters.Apertium ¶
Apertium(
source=None,
target=None,
intermediary=None,
pack_dir=None,
)
Bases: AbstractInterpreter
Apertium translation interpreter.
Provides translation capabilities using the Apertium translation engine, with support for direct translation and intermediary language pairs.
Attributes:
| Name | Type | Description |
|---|---|---|
name | Identifier for this interpreter ('APERTIUM'). | |
repository | ApertiumRepository instance for package management. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source | Optional[str] | Source language code. | None |
target | Optional[str] | Target language code. | None |
intermediary | Optional[str] | Optional intermediary language for indirect translation. | None |
pack_dir | Optional[str] | Directory for storing translation packages. | None |
Raises:
| Type | Description |
|---|---|
Exception | If the language pair is not available in the repository. |
Source code in es_translator/interpreters/apertium/apertium.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
any_pair_variant_in_packages property ¶
any_pair_variant_in_packages
Check if any variant of the current pair exists in packages.
Returns:
| Type | Description |
|---|---|
bool | True if the pair is available in remote repository. |
intermediary_pairs property ¶
intermediary_pairs
Get intermediary language pairs for indirect translation.
Automatically finds an intermediary language if not specified by building a language tree and finding a path from source to target.
Returns:
| Type | Description |
|---|---|
list[str] | List of two language pair strings for indirect translation. |
intermediary_source_pair property ¶
intermediary_source_pair
Get source-to-intermediary language pair.
Returns:
| Type | Description |
|---|---|
str | Language pair string (e.g., 'eng-spa'). |
intermediary_source_pair_package property ¶
intermediary_source_pair_package
Get package name for source-to-intermediary pair.
Returns:
| Type | Description |
|---|---|
Optional[str] | Package name string or None if not found. |
intermediary_target_pair property ¶
intermediary_target_pair
Get intermediary-to-target language pair.
Returns:
| Type | Description |
|---|---|
str | Language pair string (e.g., 'spa-fra'). |
intermediary_target_pair_package property ¶
intermediary_target_pair_package
Get package name for intermediary-to-target pair.
Returns:
| Type | Description |
|---|---|
Optional[str] | Package name string or None if not found. |
is_pair_available property ¶
is_pair_available
Check if the language pair is available locally.
Returns:
| Type | Description |
|---|---|
bool | True if pair is available without intermediary. |
local_pairs property ¶
local_pairs
Get locally installed language pairs.
Returns:
| Type | Description |
|---|---|
list[str] | List of locally available language pair codes. |
pair_package property ¶
pair_package
Get the package name for the current language pair.
Returns:
| Type | Description |
|---|---|
Optional[str] | Package name string or None if not found. |
pairs_pipeline property ¶
pairs_pipeline
Get the translation pipeline (direct or via intermediary).
Returns:
| Type | Description |
|---|---|
list[str] | List of language pair codes to process sequentially. |
remote_pairs cached property ¶
remote_pairs
Get remotely available language pairs from repository.
Returns:
| Type | Description |
|---|---|
list[str] | List of available language pair codes from the repository. |
download_intermediary_pairs ¶
download_intermediary_pairs()
Download both intermediary language pairs for indirect translation.
Source code in es_translator/interpreters/apertium/apertium.py
260 261 262 263 | |
download_necessary_pairs ¶
download_necessary_pairs()
Download required language pair packages.
Downloads either a direct pair or intermediary pairs depending on availability in the repository.
Source code in es_translator/interpreters/apertium/apertium.py
226 227 228 229 230 231 232 233 234 235 236 | |
download_pair ¶
download_pair(pair=None)
Download and install a specific language pair package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair | Optional[str] | Language pair to download. If None, uses current pair. | None |
Returns:
| Type | Description |
|---|---|
str | Path to the installed package directory. |
Source code in es_translator/interpreters/apertium/apertium.py
238 239 240 241 242 243 244 245 246 247 248 249 | |
first_pairs_path ¶
first_pairs_path(leaf, lang)
Find the first path from a tree leaf to a target language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
leaf | dict | Tree node dictionary with 'lang' and 'children' keys. | required |
lang | str | Target language to find path to. | required |
Returns:
| Type | Description |
|---|---|
list[str] | List of language codes forming the path. |
Source code in es_translator/interpreters/apertium/apertium.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
lang_tree ¶
lang_tree(lang, pairs, depth=2)
Build a tree of language connections from available pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang | str | Root language for the tree. | required |
pairs | list[list[str]] | List of language pair lists. | required |
depth | int | Maximum depth to traverse (default: 2). | 2 |
Returns:
| Type | Description |
|---|---|
dict | Dictionary tree structure with 'lang' and 'children' keys. |
Source code in es_translator/interpreters/apertium/apertium.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
leaf_has_lang ¶
leaf_has_lang(leaf, lang)
Check if a tree leaf contains or leads to a target language.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
leaf | dict | Tree node dictionary with 'lang' and 'children' keys. | required |
lang | str | Target language to search for. | required |
Returns:
| Type | Description |
|---|---|
bool | True if the language is found in the leaf or its descendants. |
Source code in es_translator/interpreters/apertium/apertium.py
301 302 303 304 305 306 307 308 309 310 311 312 | |
pair_to_pair_package ¶
pair_to_pair_package(pair)
Convert language pair to package name.
Checks both the pair and its reverse for availability in remote packages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair | str | Language pair string (e.g., 'en-es'). | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Package name if found, None otherwise. |
Source code in es_translator/interpreters/apertium/apertium.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
translate ¶
translate(input)
Translate text through the translation pipeline.
If using an intermediary language, translates through multiple pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | str | Text to translate. | required |
Returns:
| Type | Description |
|---|---|
str | Translated text string. |
Source code in es_translator/interpreters/apertium/apertium.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
translate_with_apertium ¶
translate_with_apertium(input, pair)
Translate text using Apertium for a specific language pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input | str | Text to translate. | required |
pair | str | Language pair code (e.g., 'eng-spa'). | required |
Returns:
| Type | Description |
|---|---|
str | Translated text string. |
Raises:
| Type | Description |
|---|---|
Exception | If translation fails. |
Source code in es_translator/interpreters/apertium/apertium.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
Repository Management¶
es_translator.interpreters.apertium.repository.ApertiumRepository ¶
ApertiumRepository(cache_dir=None, arch=None)
Manages Apertium package repository operations.
Handles downloading, extracting, and installing Apertium translation pairs from the official repository.
Attributes:
| Name | Type | Description |
|---|---|---|
cache_dir | Directory path for caching downloaded packages. | |
arch | System architecture ('amd64', 'i386', etc.). |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir | Optional[str] | Directory for caching downloaded packages. Defaults to None. | None |
arch | Optional[str] | Architecture string ('amd64', 'i386'). If None, auto-detect. | None |
Source code in es_translator/interpreters/apertium/repository.py
77 78 79 80 81 82 83 84 85 | |
control_file_content cached property ¶
control_file_content
Fetch and cache the Packages control file content.
Returns:
| Type | Description |
|---|---|
str | Decoded UTF-8 content of the Packages file. |
Raises:
| Type | Description |
|---|---|
URLError | If the URL cannot be accessed. |
HTTPError | If HTTP request fails. |
packages cached property ¶
packages
Parse and cache the list of available packages.
Returns:
| Type | Description |
|---|---|
list[dict] | List of package metadata dictionaries. |
packages_file_url property ¶
packages_file_url
Get the Packages file URL for the configured architecture.
pair_packages cached property ¶
pair_packages
Get filtered list of Apertium translation pair packages.
Returns:
| Type | Description |
|---|---|
list[dict] | List of package dictionaries that are translation pairs. |
clear_modes ¶
clear_modes()
Remove all mode files from the cache directory.
Source code in es_translator/interpreters/apertium/repository.py
375 376 377 378 | |
create_pair_package_alias ¶
create_pair_package_alias(package_dir)
Create symbolic links for alternative language code formats.
Creates aliases between ISO 639-1 (2-letter) and ISO 639-3 (3-letter) codes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_dir | str | Directory containing the extracted package. | required |
Returns:
| Type | Description |
|---|---|
str | Path to the created alias directory. |
Source code in es_translator/interpreters/apertium/repository.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
download_package ¶
download_package(name, force=False)
Download a package from the repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Package name to download. | required |
force | bool | If True, re-download even if package already exists. | False |
Returns:
| Type | Description |
|---|---|
str | Path to the downloaded .deb file. |
Raises:
| Type | Description |
|---|---|
PackageNotFoundError | If package cannot be found. |
Source code in es_translator/interpreters/apertium/repository.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
download_pair_package ¶
download_pair_package(pair)
Download a translation pair package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair | str | Language pair in format 'source-target'. | required |
Returns:
| Type | Description |
|---|---|
str | Path to the downloaded .deb file. |
Raises:
| Type | Description |
|---|---|
PairPackageNotFoundError | If no pair package is available for the given languages. |
Source code in es_translator/interpreters/apertium/repository.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
extract_pair_package ¶
extract_pair_package(file, extraction_dir='.')
Extract a translation pair .deb package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file | str | Path to the .deb file to extract. | required |
extraction_dir | str | Directory to extract files into. Defaults to '.'. | '.' |
Returns:
| Type | Description |
|---|---|
str | Path to the working directory containing extracted files. |
Source code in es_translator/interpreters/apertium/repository.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
find_latest_package_in_pool ¶
find_latest_package_in_pool(package_name, filename)
Find latest package version from pool directory.
Used as fallback when the Packages file lists an outdated version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name | str | Name of the package to find. | required |
filename | str | Original filename from Packages file (used to determine pool directory). | required |
Returns:
| Type | Description |
|---|---|
str | URL of the latest package version found. |
Raises:
| Type | Description |
|---|---|
Exception | If no matching package is found in the pool directory. |
URLError | If the pool directory cannot be accessed. |
Source code in es_translator/interpreters/apertium/repository.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
find_package ¶
find_package(package)
Find a package by name or provided name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package | str | Package name to search for. | required |
Returns:
| Type | Description |
|---|---|
Optional[dict] | Package metadata dictionary if found, None otherwise. |
Source code in es_translator/interpreters/apertium/repository.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
find_pair_package ¶
find_pair_package(pair)
Find a translation pair package.
Searches for both forward (source-target) and reverse (target-source) pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair | str | Language pair in format 'source-target'. | required |
Returns:
| Type | Description |
|---|---|
Optional[dict] | Package metadata dictionary if found, None otherwise. |
Source code in es_translator/interpreters/apertium/repository.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
import_modes ¶
import_modes(clear=True)
Import all mode files from installed packages into the modes directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
clear | bool | If True, clear existing modes before importing. Defaults to True. | True |
Source code in es_translator/interpreters/apertium/repository.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
install_pair_package ¶
install_pair_package(pair)
Download, extract, and install a translation pair package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair | str | Language pair in format 'source-target'. | required |
Returns:
| Type | Description |
|---|---|
str | Path to the installed package directory. |
Source code in es_translator/interpreters/apertium/repository.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
is_apertium_pair ¶
is_apertium_pair(control)
Check if a package is an Apertium translation pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
control | dict | Package metadata dictionary. | required |
Returns:
| Type | Description |
|---|---|
bool | True if package is a translation pair (format: apertium-XX-YY). |
Source code in es_translator/interpreters/apertium/repository.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
replace_in_file ¶
replace_in_file(file, target, replacement)
Replace all occurrences of target string in a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file | str | Path to the file to modify. | required |
target | str | String to search for. | required |
replacement | str | String to replace with. | required |
Source code in es_translator/interpreters/apertium/repository.py
293 294 295 296 297 298 299 300 301 302 303 | |