Translator Class
Translator
¶
This class defines and stores a language model (such as MarianMT) for the translation task, from source_language to target_language. It also provides functions to perform full translations efficiently from extracted subtitles.
Warning
The translation model will be download from HugginFace servers and cached for a faster load next time. For each (source_language, target_language) pair, there is a distinct model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_language |
AvailableLanguages
|
Language of the source subtitles. |
required |
target_language |
AvailableLanguages
|
Target language. |
required |
Source code in subtitles_translator/translator.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 |
|
progressBar(iterable, prefix='', suffix='', decimals=1, length=100, fill='█', print_end='\r')
staticmethod
¶
Call in a loop to create terminal progress bar. Source : https://stackoverflow.com/questions/3173320/text-progress-bar-in-terminal-with-block-characters/13685020
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iterable |
Iterable
|
Iterable object |
required |
prefix |
str
|
Prefix string |
''
|
suffix |
str
|
Suffix string |
''
|
decimals |
int
|
Positive number of decimals in percent complete |
1
|
length |
int, optional)
|
Character length of bar |
100
|
fill |
str
|
Bar fill character (Str) |
'█'
|
print_end |
str
|
End character |
'\r'
|
Source code in subtitles_translator/translator.py
85 86 87 88 89 90 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 |
|
translate(input_text)
¶
Translate a text input using the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_text |
str
|
Text to be translated (usually, a single sentence) |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Translated text. |
Source code in subtitles_translator/translator.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
translate_subtitles(subtitles)
¶
Use given translator to perform translation using dictionary of aggregated subtitles lines. Each translated line replaces the original one in the full_text_line list created at the beginning of the process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subtitles |
Subtitles object
|
Object of the Subtitles class. |
required |
Source code in subtitles_translator/translator.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 |
|