From 06f7b7bfb4e6a0d2022331e9c130db8f043fb501 Mon Sep 17 00:00:00 2001 From: Alexander Schomburg Date: Tue, 30 Nov 2021 20:45:22 +0100 Subject: [PATCH] Updated to use cont-init.d logic and added local translation option. --- Dockerfile | 15 ++++++++----- README.md | 9 ++++++-- .../cont-init.d/92-projectsend-translations | 21 +++++++++++++++++++ root/install-translations.sh | 16 -------------- 4 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 root/etc/cont-init.d/92-projectsend-translations delete mode 100644 root/install-translations.sh diff --git a/Dockerfile b/Dockerfile index 752385a..2c8793f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,15 @@ +FROM lsiobase/alpine:3.11 as buildstage + +# copy local files +COPY root/ /root-layer/ + +# runtime stage FROM scratch LABEL maintainer="alexschomb" -# copy local files -COPY root/ / +# Add files from buildstage +COPY --from=buildstage /root-layer/ / -# install translations -RUN chmod +x /install-translations.sh -CMD /install-translations.sh +# volumes +VOLUME /translations \ No newline at end of file diff --git a/README.md b/README.md index 942b876..460dcb3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Translations - Docker mod for projectsend -This mod adds installation options for adding translations to the [Docker image of LinuxServer.io](https://github.com/linuxserver/docker-projectsend) for [ProjectSend](http://www.projectsend.org/). The translations to be installed can be defined with ``TRANSLATIONS`` as a comma-separated list and will be automatically downloaded from the [official translations website](https://www.projectsend.org/translations/). To help translating (and adding your preferred language to) ProjectSend, please follow [this link](https://www.transifex.com/subwaydesign/projectsend/). +This mod adds installation options for adding translations to the [Docker image of LinuxServer.io](https://github.com/linuxserver/docker-projectsend) for [ProjectSend](http://www.projectsend.org/). The translations to be installed can be defined with ``TRANSLATIONS`` as a comma-separated list and can be either be automatically installed from the [official translations website](https://www.projectsend.org/translations/) or the local ``/translations`` volume. To help translating (and adding your preferred language to) ProjectSend, please follow [this link](https://www.transifex.com/subwaydesign/projectsend/). ## Using this Docker Mod To add this Docker Mod to your installation of the ProjectSend [Docker image of LinuxServer.io](https://github.com/linuxserver/docker-projectsend), please add this endpoint ``linuxserver/mods:projectsend-translations`` to the ``DOCKER_MODS`` environment variable. You can install multiple Docker Mods by separating them by ``|``. [Read this page](https://github.com/linuxserver/docker-mods#using-a-docker-mod) for more information. -Now, you can define the languages/translations to be installed with their "Lang. code" value from the before mentioned [official translations website](https://www.projectsend.org/translations/) to the ``TRANSLATIONS`` environment variable. You can choose to install multiple translations by separating them with commas. The English translation ``en`` is automatically installed by the ProjectSend image and does not have to be addressed by this Docker Mod or the ``TRANSLATIONS`` environment variable. +Now, you can define the languages/translations to be installed with their name to the ``TRANSLATIONS`` environment variable. You can choose to install multiple translations by separating them with commas. You can either install them by providing the folder name of a subfolder in the new ``/translations`` volume, or the "Lang. code" value from the before mentioned [official translations website](https://www.projectsend.org/translations/). The English translation ``en`` is automatically installed by the ProjectSend image and does not have to be addressed by this Docker Mod or the ``TRANSLATIONS`` environment variable. Full example with ``docker-compose``: @@ -27,10 +27,15 @@ services: volumes: - :/config - :/data + - :/translations ports: - 80:80 restart: unless-stopped ``` +### Known limitations + +* Translations will only update when rebuilding the base image (``docker-compose down && docker-compose up -d --rebuild``), a simple ``docker-compose restart`` is not sufficient. This is because the [Docker image of LinuxServer.io](https://github.com/linuxserver/docker-projectsend) does not work with mounted volumes inside ``/app/projectsend/``. As a result, translation development can be very uncomfortable using this approach. Sorry. + ## Source / References I took inspiration from the Dockerfile of the [Grafana](https://github.com/grafana/grafana/) repository, especially [this file](https://github.com/grafana/grafana/blob/main/packaging/docker/run.sh). Thanks! diff --git a/root/etc/cont-init.d/92-projectsend-translations b/root/etc/cont-init.d/92-projectsend-translations new file mode 100644 index 0000000..c9a8334 --- /dev/null +++ b/root/etc/cont-init.d/92-projectsend-translations @@ -0,0 +1,21 @@ +#!/usr/bin/with-contenv bash + +if [ ! -z "${TRANSLATIONS}" ]; then + OLDIFS=$IFS + IFS=',' + for translation in ${TRANSLATIONS}; do + IFS=$OLDIFS + if [[ -d "/translations/${translation}" ]]; then + echo "**** install local translation: ${translation} ****" + cp -R "/translations/${translation}/*" /app/projectsend/ + else + echo "**** install online translation: ${translation} ****" + curl -s -o "/tmp/${translation}.zip" -L "https://www.projectsend.org/translations/get.php?lang=${translation}" + unzip -o "/tmp/${translation}.zip" -d /app/projectsend; + fi + done + echo "**** cleanup ****" + rm -rf /tmp/* +fi + +while :; do :; done & kill -STOP $! && wait $! \ No newline at end of file diff --git a/root/install-translations.sh b/root/install-translations.sh deleted file mode 100644 index 134adef..0000000 --- a/root/install-translations.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -e - -if [ ! -z "${TRANSLATIONS}" ]; then - OLDIFS=$IFS - IFS=',' - for translation in ${TRANSLATIONS}; do - IFS=$OLDIFS - echo "**** install translation: ${translation} ****" - curl -s -o "/tmp/${translation}.zip" -L "https://www.projectsend.org/translations/get.php?lang=${translation}" - unzip -o "/tmp/${translation}.zip" -d /app/projectsend; - done - echo "**** cleanup ****" - rm -rf /tmp/* -fi - -while :; do :; done & kill -STOP $! && wait $! \ No newline at end of file