From d9474c3dd6b5febd6226c8ec5039ccfe6a1ad3a0 Mon Sep 17 00:00:00 2001 From: "push-app-to-main[bot]" <203845782+push-app-to-main[bot]@users.noreply.github.com> Date: Sun, 15 Jun 2025 20:55:01 +0200 Subject: [PATCH] LibreTranslate (#5154) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: push-app-to-main[bot] <203845782+push-app-to-main[bot]@users.noreply.github.com> Co-authored-by: Slaviša Arežina <58952836+tremor021@users.noreply.github.com> --- ct/headers/libretranslate | 6 ++ ct/libretranslate.sh | 61 +++++++++++++++++++ frontend/public/json/libretranslate.json | 44 ++++++++++++++ install/libretranslate-install.sh | 76 ++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 ct/headers/libretranslate create mode 100644 ct/libretranslate.sh create mode 100644 frontend/public/json/libretranslate.json create mode 100644 install/libretranslate-install.sh diff --git a/ct/headers/libretranslate b/ct/headers/libretranslate new file mode 100644 index 000000000..bf4c68627 --- /dev/null +++ b/ct/headers/libretranslate @@ -0,0 +1,6 @@ + __ _ __ ______ __ __ + / / (_) /_ ________/_ __/________ _____ _____/ /___ _/ /____ + / / / / __ \/ ___/ _ \/ / / ___/ __ `/ __ \/ ___/ / __ `/ __/ _ \ + / /___/ / /_/ / / / __/ / / / / /_/ / / / (__ ) / /_/ / /_/ __/ +/_____/_/_.___/_/ \___/_/ /_/ \__,_/_/ /_/____/_/\__,_/\__/\___/ + diff --git a/ct/libretranslate.sh b/ct/libretranslate.sh new file mode 100644 index 000000000..12e529af0 --- /dev/null +++ b/ct/libretranslate.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Slaviša Arežina (tremor021) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/LibreTranslate/LibreTranslate + +APP="LibreTranslate" +var_tags="${var_tags:-Arr}" +var_cpu="${var_cpu:-2}" +var_ram="${var_ram:-2048}" +var_disk="${var_disk:-20}" +var_os="${var_os:-debian}" +var_version="${var_version:-12}" +var_unprivileged="${var_unprivileged:-1}" + +header_info "$APP" +variables +color +catch_errors + +function update_script() { + header_info + check_container_storage + check_container_resources + + if [[ ! -d /opt/libretranslate ]]; then + msg_error "No ${APP} Installation Found!" + exit + fi + RELEASE=$(curl -s https://api.github.com/repos/LibreTranslate/LibreTranslate/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') + if [[ "${RELEASE}" != "$(cat $HOME/.libretranslate)" ]] || [[ ! -f $HOME/.libretranslate ]]; then + msg_info "Stopping $APP" + systemctl stop libretranslate + msg_ok "Stopped $APP" + + msg_info "Updating $APP to ${RELEASE}" + cd /opt/libretranslate + source .venv/bin/activate + $STD pip install -U libretranslate + msg_ok "Updated $APP to ${RELEASE}" + + msg_info "Starting $APP" + systemctl start libretranslate + msg_ok "Started $APP" + + msg_ok "Update Successful" + else + msg_ok "No update required. ${APP} is already at ${RELEASE}" + fi + exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" +echo -e "${INFO}${YW} Access it using the following URL:${CL}" +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:5000${CL}" diff --git a/frontend/public/json/libretranslate.json b/frontend/public/json/libretranslate.json new file mode 100644 index 000000000..5d90bf4bd --- /dev/null +++ b/frontend/public/json/libretranslate.json @@ -0,0 +1,44 @@ +{ + "name": "LibreTranslate", + "slug": "libretranslate", + "categories": [ + 0 + ], + "date_created": "2025-06-13", + "type": "ct", + "updateable": true, + "privileged": false, + "interface_port": 5000, + "documentation": "https://github.com/LibreTranslate/LibreTranslate?tab=readme-ov-file#settings--flags", + "website": "https://libretranslate.com/", + "logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/libretranslate.webp", + "config_path": "", + "description": "Free and Open Source Machine Translation API, entirely self-hosted. Unlike other APIs, it doesn't rely on proprietary providers such as Google or Azure to perform translations. Instead, its translation engine is powered by the open source Argos Translate library.", + "install_methods": [ + { + "type": "default", + "script": "ct/libretranslate.sh", + "resources": { + "cpu": 2, + "ram": 2048, + "hdd": 20, + "os": "debian", + "version": "12" + } + } + ], + "default_credentials": { + "username": null, + "password": null + }, + "notes": [ + { + "text": "During the installation, application will download language models used for translation. Depending on how fast your internet/host is, this can take 5-10 minutes.", + "type": "info" + }, + { + "text": "At every boot of LXC, application will look for updates for language models installed. This can prolong the startup of the LXC.", + "type": "info" + } + ] +} diff --git a/install/libretranslate-install.sh b/install/libretranslate-install.sh new file mode 100644 index 000000000..6779f0397 --- /dev/null +++ b/install/libretranslate-install.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2025 community-scripts ORG +# Author: Slaviša Arežina (tremor021) +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE +# Source: https://github.com/LibreTranslate/LibreTranslate + +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing dependencies" +$STD apt-get install -y --no-install-recommends \ + pkg-config \ + gcc \ + g++ \ + libicu-dev +msg_ok "Installed dependencies" + +msg_info "Setup Python3" +$STD apt-get install -y \ + python3-pip \ + python3-dev \ + python3-icu +msg_ok "Setup Python3" + +setup_uv +fetch_and_deploy_gh_release "LibreTranslate/LibreTranslate" + +msg_info "Setup LibreTranslate (Patience)" +cd /opt/libretranslate +$STD uv venv .venv +$STD source .venv/bin/activate +$STD uv pip install --upgrade pip setuptools +$STD uv pip install Babel==2.12.1 +$STD .venv/bin/python scripts/compile_locales.py +$STD uv pip install torch==2.2.0 --extra-index-url https://download.pytorch.org/whl/cpu +$STD uv pip install "numpy<2" +$STD uv pip install . +$STD uv pip install libretranslate +$STD .venv/bin/python scripts/install_models.py +msg_ok "Installed LibreTranslate" + +msg_info "Creating Service" +cat </etc/systemd/system/libretranslate.service +[Unit] +Description=LibreTranslate +After=network.target + +[Service] +User=root +Type=idle +Restart=always +Environment="PATH=/usr/local/lib/python3.11/dist-packages/libretranslate" +ExecStart=/opt/libretranslate/.venv/bin/python3 /opt/libretranslate/.venv/bin/libretranslate --host * --update-models +ExecReload=/bin/kill -s HUP +KillMode=mixed +TimeoutStopSec=1 + +[Install] +WantedBy=multi-user.target +EOF +systemctl enable -q --now libretranslate +msg_ok "Created Service" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned"