mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-22 07:51:00 +00:00
download the transliteration packages of polyglot during boot
This commit is contained in:
parent
25fb3b3c21
commit
e0693d697e
2 changed files with 29 additions and 3 deletions
25
app/init.py
25
app/init.py
|
@ -2,9 +2,12 @@ import os
|
|||
from pathlib import Path
|
||||
from argostranslate import settings, package, translate
|
||||
import os, glob, shutil, zipfile
|
||||
from app.language import languages
|
||||
import polyglot
|
||||
|
||||
def boot():
|
||||
check_and_install_models()
|
||||
check_and_install_transliteration()
|
||||
|
||||
def check_and_install_models(force=False):
|
||||
if len(package.get_installed_packages()) < 2 or force:
|
||||
|
@ -24,3 +27,25 @@ def check_and_install_models(force=False):
|
|||
|
||||
print("Loaded support for %s languages (%s models total)!" % (len(translate.load_installed_languages()), len(available_packages)))
|
||||
|
||||
|
||||
def check_and_install_transliteration(force=False):
|
||||
# 'en' is not a supported transliteration language
|
||||
transliteration_languages = [l.code for l in languages if l.code != "en"]
|
||||
|
||||
# check installed
|
||||
install_needed = []
|
||||
if not force:
|
||||
t_packages_path = Path(polyglot.polyglot_path) / "transliteration2"
|
||||
for lang in transliteration_languages:
|
||||
if not (t_packages_path / lang / f"transliteration.{lang}.tar.bz2").exists():
|
||||
install_needed.append(lang)
|
||||
else:
|
||||
install_needed = transliteration_languages
|
||||
|
||||
# install the needed transliteration packages
|
||||
if install_needed:
|
||||
from polyglot.downloader import Downloader
|
||||
downloader = Downloader()
|
||||
|
||||
for lang in install_needed:
|
||||
downloader.download(f"transliteration2.{lang}")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from app.init import check_and_install_models
|
||||
from app.init import check_and_install_models, check_and_install_transliteration
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_and_install_models(force=True)
|
||||
check_and_install_transliteration(force=True)
|
||||
|
|
Loading…
Reference in a new issue