forked from mozilla/firefox-translations-models
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add argos translator to the comparison
Part of mozilla/translations#179
Showing
4 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ pandas==1.1.5 | |
matplotlib==3.4.2 | ||
mtdata==0.2.9 | ||
unbabel-comet==2.1.1 | ||
argostranslate==1.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
import argostranslate.package | ||
import argostranslate.translate | ||
import sys | ||
|
||
from tqdm import tqdm | ||
|
||
|
||
def translate(texts, source, target): | ||
return [argostranslate.translate.translate(text, source, target) for text in tqdm(texts)] | ||
|
||
|
||
if __name__ == '__main__': | ||
texts = [line.strip() for line in sys.stdin] | ||
|
||
source = os.environ['SRC'] | ||
target = os.environ['TRG'] | ||
|
||
argostranslate.package.update_package_index() | ||
available_packages = argostranslate.package.get_available_packages() | ||
package_to_install = next( | ||
filter( | ||
lambda x: x.from_code == source and x.to_code == target, available_packages | ||
) | ||
) | ||
argostranslate.package.install_from_path(package_to_install.download()) | ||
|
||
translations = translate(texts, source, target) | ||
sys.stdout.write('\n'.join(translations)) | ||
sys.stdout.write('\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters