Skip to content

Commit 56a1bdd

Browse files
committed
feat: add i18n in install.py
1 parent ebc0322 commit 56a1bdd

11 files changed

+276
-59
lines changed

install.py

+62-33
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import os
1+
import os, sys
22
import platform
33
import subprocess
4-
import sys
54
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
65

76
ascii_logo = """
@@ -19,63 +18,70 @@ def install_package(*packages):
1918
def check_nvidia_gpu():
2019
install_package("pynvml")
2120
import pynvml
21+
from translations.translations import translate as t
2222
try:
2323
pynvml.nvmlInit()
2424
device_count = pynvml.nvmlDeviceGetCount()
2525
if device_count > 0:
26-
print(f"Detected NVIDIA GPU(s)")
26+
print(t("Detected NVIDIA GPU(s)"))
2727
for i in range(device_count):
2828
handle = pynvml.nvmlDeviceGetHandleByIndex(i)
2929
name = pynvml.nvmlDeviceGetName(handle)
3030
print(f"GPU {i}: {name}")
3131
return True
3232
else:
33-
print("No NVIDIA GPU detected")
33+
print(t("No NVIDIA GPU detected"))
3434
return False
3535
except pynvml.NVMLError:
36-
print("No NVIDIA GPU detected or NVIDIA drivers not properly installed")
36+
print(t("No NVIDIA GPU detected or NVIDIA drivers not properly installed"))
3737
return False
3838
finally:
3939
pynvml.nvmlShutdown()
4040

4141
def check_ffmpeg():
4242
from rich.console import Console
4343
from rich.panel import Panel
44+
from translations.translations import translate as t
4445
console = Console()
45-
46+
4647
try:
4748
# Check if ffmpeg is installed
4849
subprocess.run(['ffmpeg', '-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
49-
console.print(Panel("✅ FFmpeg is already installed", style="green"))
50+
console.print(Panel(t("✅ FFmpeg is already installed"), style="green"))
5051
return True
5152
except (subprocess.CalledProcessError, FileNotFoundError):
5253
system = platform.system()
5354
install_cmd = ""
5455

5556
if system == "Windows":
5657
install_cmd = "choco install ffmpeg"
57-
extra_note = "Install Chocolatey first (https://chocolatey.org/)"
58+
extra_note = t("Install Chocolatey first (https://chocolatey.org/)")
5859
elif system == "Darwin":
5960
install_cmd = "brew install ffmpeg"
60-
extra_note = "Install Homebrew first (https://brew.sh/)"
61+
extra_note = t("Install Homebrew first (https://brew.sh/)")
6162
elif system == "Linux":
6263
install_cmd = "sudo apt install ffmpeg # Ubuntu/Debian\nsudo yum install ffmpeg # CentOS/RHEL"
63-
extra_note = "Use your distribution's package manager"
64+
extra_note = t("Use your distribution's package manager")
6465

6566
console.print(Panel.fit(
66-
f"❌ FFmpeg not found\n\n"
67-
f"🛠️ Install using:\n[bold cyan]{install_cmd}[/bold cyan]\n\n"
68-
f"💡 Note: {extra_note}\n\n"
69-
f"🔄 After installing FFmpeg, please run this installer again: [bold cyan]python install.py[/bold cyan]",
67+
t("❌ FFmpeg not found\n\n") +
68+
f"{t('🛠️ Install using:')}\n[bold cyan]{install_cmd}[/bold cyan]\n\n" +
69+
f"{t('💡 Note:')}\n{extra_note}\n\n" +
70+
f"{t('🔄 After installing FFmpeg, please run this installer again:')}\n[bold cyan]python install.py[/bold cyan]",
7071
style="red"
7172
))
72-
raise SystemExit("FFmpeg is required. Please install it and run the installer again.")
73+
raise SystemExit(t("FFmpeg is required. Please install it and run the installer again."))
7374

7475
def main():
75-
install_package("requests", "rich", "ruamel.yaml")
76+
install_package("requests", "rich", "ruamel.yaml", "InquirerPy")
7677
from rich.console import Console
7778
from rich.panel import Panel
7879
from rich.box import DOUBLE
80+
from InquirerPy import inquirer
81+
from translations.translations import translate as t
82+
from translations.translations import DISPLAY_LANGUAGES
83+
from core.config_utils import load_key, update_key
84+
7985
console = Console()
8086

8187
width = max(len(line) for line in ascii_logo.splitlines()) + 4
@@ -87,21 +93,36 @@ def main():
8793
border_style="bright_blue"
8894
)
8995
console.print(welcome_panel)
90-
91-
console.print(Panel.fit("🚀 Starting Installation", style="bold magenta"))
96+
# Language selection
97+
current_language = load_key("display_language")
98+
# Find the display name for current language code
99+
current_display = next((k for k, v in DISPLAY_LANGUAGES.items() if v == current_language), "🇬🇧 English")
100+
selected_language = DISPLAY_LANGUAGES[inquirer.select(
101+
message="Select language / 选择语言 / 選擇語言 / 言語を選択 / Seleccionar idioma / Sélectionner la langue / Выберите язык:",
102+
choices=list(DISPLAY_LANGUAGES.keys()),
103+
default=current_display
104+
).execute()]
105+
update_key("display_language", selected_language)
106+
107+
console.print(Panel.fit(t("🚀 Starting Installation"), style="bold magenta"))
92108

93109
# Configure mirrors
94-
from core.pypi_autochoose import main as choose_mirror
95-
choose_mirror()
110+
# add a check to ask user if they want to configure mirrors
111+
if inquirer.confirm(
112+
message=t("Do you need to auto-configure PyPI mirrors? (Recommended if you have difficulty accessing pypi.org)"),
113+
default=True
114+
).execute():
115+
from core.pypi_autochoose import main as choose_mirror
116+
choose_mirror()
96117

97118
# Detect system and GPU
98119
has_gpu = platform.system() != 'Darwin' and check_nvidia_gpu()
99120
if has_gpu:
100-
console.print(Panel("🎮 NVIDIA GPU detected, installing CUDA version of PyTorch...", style="cyan"))
121+
console.print(Panel(t("🎮 NVIDIA GPU detected, installing CUDA version of PyTorch..."), style="cyan"))
101122
subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.0.0", "torchaudio==2.0.0", "--index-url", "https://download.pytorch.org/whl/cu118"])
102123
else:
103124
system_name = "🍎 MacOS" if platform.system() == 'Darwin' else "💻 No NVIDIA GPU"
104-
console.print(Panel(f"{system_name} detected, installing CPU version of PyTorch... However, it would be extremely slow for transcription.", style="cyan"))
125+
console.print(Panel(t(f"{system_name} detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription."), style="cyan"))
105126
subprocess.check_call([sys.executable, "-m", "pip", "install", "torch==2.1.2", "torchaudio==2.1.2"])
106127

107128
def install_requirements():
@@ -115,7 +136,7 @@ def install_requirements():
115136
"requirements.txt"
116137
], env={**os.environ, "PIP_NO_CACHE_DIR": "0", "PYTHONIOENCODING": "utf-8"})
117138
except subprocess.CalledProcessError as e:
118-
console.print(Panel(f"❌ Failed to install requirements: {str(e)}", style="red"))
139+
console.print(Panel(t("❌ Failed to install requirements:") + str(e), style="red"))
119140

120141
def install_noto_font():
121142
# Detect Linux distribution type
@@ -128,7 +149,7 @@ def install_noto_font():
128149
cmd = ['sudo', 'yum', 'install', '-y', 'google-noto*']
129150
pkg_manager = "yum"
130151
else:
131-
console.print("⚠️ Unrecognized Linux distribution, please install Noto fonts manually", style="yellow")
152+
console.print("Warning: Unrecognized Linux distribution, please install Noto fonts manually", style="yellow")
132153
return
133154

134155
try:
@@ -140,18 +161,26 @@ def install_noto_font():
140161
if platform.system() == 'Linux':
141162
install_noto_font()
142163

164+
console.print(Panel(t("Installing requirements using `pip install -r requirements.txt`"), style="cyan"))
143165
install_requirements()
144166
check_ffmpeg()
145167

146-
console.print(Panel.fit("Installation completed", style="bold green"))
147-
console.print("To start the application, run:")
148-
console.print("[bold cyan]streamlit run st.py[/bold cyan]")
149-
console.print("[yellow]Note: First startup may take up to 1 minute[/yellow]")
150-
151-
# Add troubleshooting tips
152-
console.print("\n[yellow]If the application fails to start:[/yellow]")
153-
console.print("1. [yellow]Check your network connection[/yellow]")
154-
console.print("2. [yellow]Re-run the installer: [bold]python install.py[/bold][/yellow]")
168+
# First panel with installation complete and startup command
169+
panel1_text = (
170+
t("Installation completed") + "\n\n" +
171+
t("Now I will run this command to start the application:") + "\n" +
172+
"[bold]streamlit run st.py[/bold]\n" +
173+
t("Note: First startup may take up to 1 minute")
174+
)
175+
console.print(Panel(panel1_text, style="bold green"))
176+
177+
# Second panel with troubleshooting tips
178+
panel2_text = (
179+
t("If the application fails to start:") + "\n" +
180+
"1. " + t("Check your network connection") + "\n" +
181+
"2. " + t("Re-run the installer: [bold]python install.py[/bold]")
182+
)
183+
console.print(Panel(panel2_text, style="yellow"))
155184

156185
# start the application
157186
subprocess.Popen(["streamlit", "run", "st.py"])

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ streamlit==1.38.0
1818
yt-dlp
1919
json-repair
2020
ruamel.yaml
21+
InquirerPy
2122
autocorrect-py
2223
ctranslate2==4.4.0
2324
edge-tts

st_components/sidebar_setting.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import streamlit as st
55
from core.config_utils import update_key, load_key
66
from translations.translations import translate as t
7+
from translations.translations import DISPLAY_LANGUAGES
78

89
def config_input(label, key, help=None):
910
"""Generic config input handler"""
@@ -14,20 +15,11 @@ def config_input(label, key, help=None):
1415

1516
def page_setting():
1617

17-
display_langs = {
18-
"🇬🇧 English": "en",
19-
"🇨🇳 简体中文": "zh-CN",
20-
"🇭🇰 繁体中文": "zh-HK",
21-
"🇯🇵 日本語": "ja",
22-
"🇪🇸 Español": "es",
23-
"🇷🇺 Русский": "ru",
24-
"🇫🇷 Français": "fr",
25-
}
2618
display_language = st.selectbox("Display Language 🌐",
27-
options=list(display_langs.keys()),
28-
index=list(display_langs.values()).index(load_key("display_language")))
29-
if display_langs[display_language] != load_key("display_language"):
30-
update_key("display_language", display_langs[display_language])
19+
options=list(DISPLAY_LANGUAGES.keys()),
20+
index=list(DISPLAY_LANGUAGES.values()).index(load_key("display_language")))
21+
if DISPLAY_LANGUAGES[display_language] != load_key("display_language"):
22+
update_key("display_language", DISPLAY_LANGUAGES[display_language])
3123
st.rerun()
3224

3325
with st.expander(t("LLM Configuration"), expanded=True):

translations/en.json

+27-1
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,31 @@
7676
"Hello, welcome to VideoLingo. If you encounter any issues, feel free to get instant answers with our Free QA Agent <a href=\"https://share.fastgpt.in/chat/share?shareId=066w11n3r9aq6879r4z0v9rh\" target=\"_blank\">here</a>! You can also try out our SaaS website at <a href=\"https://videolingo.io\" target=\"_blank\">videolingo.io</a> for free!": "Hello, welcome to VideoLingo. If you encounter any issues, feel free to get instant answers with our Free QA Agent <a href=\"https://share.fastgpt.in/chat/share?shareId=066w11n3r9aq6879r4z0v9rh\" target=\"_blank\">here</a>! You can also try out our SaaS website at <a href=\"https://videolingo.io\" target=\"_blank\">videolingo.io</a> for free!",
7777
"WhisperX Runtime": "WhisperX Runtime",
7878
"Local runtime requires >8GB GPU, cloud runtime requires 302ai API key": "Local runtime requires >8GB GPU, cloud runtime requires 302ai API key",
79-
"WhisperX 302ai API": "WhisperX 302ai API"
79+
"WhisperX 302ai API": "WhisperX 302ai API",
80+
"=====NOTE2=====": "BELOW IS in install.py",
81+
"🚀 Starting Installation": "🚀 Starting Installation",
82+
"Do you need to auto-configure PyPI mirrors? (Recommended if you have difficulty accessing pypi.org)": "Do you need to auto-configure PyPI mirrors? (Recommended if you have difficulty accessing pypi.org)",
83+
"🎮 NVIDIA GPU detected, installing CUDA version of PyTorch...": "🎮 NVIDIA GPU detected, installing CUDA version of PyTorch...",
84+
"🍎 MacOS detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription.": "🍎 MacOS detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription.",
85+
"💻 No NVIDIA GPU detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription.": "🍎 MacOS detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription.",
86+
"❌ Failed to install requirements:": "❌ Failed to install requirements:",
87+
"✅ FFmpeg is already installed": "✅ FFmpeg is already installed",
88+
"❌ FFmpeg not found\n\n": "❌ FFmpeg not found\n\n",
89+
"🛠️ Install using:": "🛠️ Install using:",
90+
"💡 Note:": "💡 Note:",
91+
"🔄 After installing FFmpeg, please run this installer again:": "🔄 After installing FFmpeg, please run this installer again:",
92+
"Install Chocolatey first (https://chocolatey.org/)": "Install Chocolatey first (https://chocolatey.org/)",
93+
"Install Homebrew first (https://brew.sh/)": "Install Homebrew first (https://brew.sh/)",
94+
"Use your distribution's package manager": "Use your distribution's package manager",
95+
"FFmpeg is required. Please install it and run the installer again.": "FFmpeg is required. Please install it and run the installer again.",
96+
"Installing requirements using `pip install -r requirements.txt`": "Installing requirements using `pip install -r requirements.txt`",
97+
"Installation completed": "Installation completed",
98+
"Now I will run this command to start the application:": "Now I will run this command to start the application:",
99+
"Note: First startup may take up to 1 minute": "Note: First startup may take up to 1 minute",
100+
"If the application fails to start:": "If the application fails to start:",
101+
"Check your network connection": "Check your network connection",
102+
"Re-run the installer: [bold]python install.py[/bold]": "Re-run the installer: [bold]python install.py[/bold]",
103+
"Detected NVIDIA GPU(s)": "Detected NVIDIA GPU(s)",
104+
"No NVIDIA GPU detected": "No NVIDIA GPU detected",
105+
"No NVIDIA GPU detected or NVIDIA drivers not properly installed": "No NVIDIA GPU detected or NVIDIA drivers not properly installed"
80106
}

translations/es.json

+27-1
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,31 @@
7676
"Hello, welcome to VideoLingo. If you encounter any issues, feel free to get instant answers with our Free QA Agent <a href=\"https://share.fastgpt.in/chat/share?shareId=066w11n3r9aq6879r4z0v9rh\" target=\"_blank\">here</a>! You can also try out our SaaS website at <a href=\"https://videolingo.io\" target=\"_blank\">videolingo.io</a> for free!": "Hola, bienvenido a VideoLingo. Si encuentra algún problema, no dude en obtener respuestas instantáneas con nuestro Agente de preguntas y respuestas gratuito <a href=\"https://share.fastgpt.in/chat/share?shareId=066w11n3r9aq6879r4z0v9rh\" target=\"_blank\">aquí</a>. ¡También puede probar gratis nuestro sitio web SaaS en <a href=\"https://videolingo.io\" target=\"_blank\">videolingo.io</a>!",
7777
"WhisperX Runtime": "Entorno de WhisperX",
7878
"Local runtime requires >8GB GPU, cloud runtime requires 302ai API key": "El entorno local requiere GPU >8GB, el entorno en la nube requiere clave API 302ai",
79-
"WhisperX 302ai API": "API 302ai de WhisperX"
79+
"WhisperX 302ai API": "API 302ai de WhisperX",
80+
"=====NOTE2=====": "A continuación está en install.py",
81+
"🚀 Starting Installation": "🚀 Iniciando instalación",
82+
"Do you need to auto-configure PyPI mirrors? (Recommended if you have difficulty accessing pypi.org)": "¿Necesita configurar automáticamente los espejos PyPI? (Recomendado si tiene dificultades para acceder a pypi.org)",
83+
"🎮 NVIDIA GPU detected, installing CUDA version of PyTorch...": "🎮 GPU NVIDIA detectada, instalando versión CUDA de PyTorch...",
84+
"🍎 MacOS detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription.": "🍎 MacOS detectado, instalando versión CPU de PyTorch... Nota: puede ser lento durante la transcripción de whisperX.",
85+
"💻 No NVIDIA GPU detected, installing CPU version of PyTorch... Note: it might be slow during whisperX transcription.": "💻 No se detectó GPU NVIDIA, instalando versión CPU de PyTorch... Nota: puede ser lento durante la transcripción de whisperX.",
86+
"❌ Failed to install requirements:": "❌ Error al instalar los requisitos:",
87+
"✅ FFmpeg is already installed": "✅ FFmpeg ya está instalado",
88+
"❌ FFmpeg not found\n\n": "❌ FFmpeg no encontrado\n\n",
89+
"🛠️ Install using:": "🛠️ Instalar usando:",
90+
"💡 Note:": "💡 Nota:",
91+
"🔄 After installing FFmpeg, please run this installer again:": "🔄 Después de instalar FFmpeg, ejecute este instalador nuevamente:",
92+
"Install Chocolatey first (https://chocolatey.org/)": "Instale Chocolatey primero (https://chocolatey.org/)",
93+
"Install Homebrew first (https://brew.sh/)": "Instale Homebrew primero (https://brew.sh/)",
94+
"Use your distribution's package manager": "Use el gestor de paquetes de su distribución",
95+
"FFmpeg is required. Please install it and run the installer again.": "Se requiere FFmpeg. Por favor instálelo y ejecute el instalador nuevamente.",
96+
"Installation completed": "Instalación completada",
97+
"Now I will run this command to start the application:": "Ahora ejecutaré este comando para iniciar la aplicación:",
98+
"Note: First startup may take up to 1 minute": "Nota: El primer inicio puede tardar hasta 1 minuto",
99+
"If the application fails to start:": "Si la aplicación no se inicia:",
100+
"Check your network connection": "Compruebe su conexión de red",
101+
"Re-run the installer: [bold]python install.py[/bold]": "Vuelva a ejecutar el instalador: [bold]python install.py[/bold]",
102+
"Installing requirements using `pip install -r requirements.txt`": "Instalando dependencias usando `pip install -r requirements.txt`",
103+
"Detected NVIDIA GPU(s)": "GPU(s) NVIDIA detectada(s)",
104+
"No NVIDIA GPU detected": "No se detectó GPU NVIDIA",
105+
"No NVIDIA GPU detected or NVIDIA drivers not properly installed": "No se detectó GPU NVIDIA o los controladores NVIDIA no están instalados correctamente"
80106
}

0 commit comments

Comments
 (0)