From a2312a608a5f995b7c2d81301730aac8ea49024b Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sat, 3 Mar 2018 10:26:54 +0100 Subject: Improve translating tools (#1808) To ease the use of the translating tools, I've added a formatting method to keep the output files identicals. This will reduce the amount of time needed to handle translations. --- cli/i18n/I18nFile.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.php index d6489ee21..627f6f580 100644 --- a/cli/i18n/I18nFile.php +++ b/cli/i18n/I18nFile.php @@ -36,8 +36,7 @@ class i18nFile { } foreach ($file as $name => $content) { $filename = $dir . DIRECTORY_SEPARATOR . $name; - $fullContent = var_export($this->unflatten($content), true); - file_put_contents($filename, sprintf('format($content)); } } } @@ -89,4 +88,32 @@ class i18nFile { return $a; } + /** + * Format an array of translation + * + * It takes an array of translation and format it to be dumped in a + * translation file. The array is first converted to a string then some + * formatting regexes are applied to match the original content. + * + * @param array $translation + * @return string + */ + private function format($translation) { + $translation = var_export($this->unflatten($translation), true); + $patterns = array( + '/array \(/', + '/=>\s*array/', + '/ {2}/', + ); + $replacements = array( + 'array(', + '=> array', + "\t", // Double quoting is mandatory to have a tab instead of the \t string + ); + $translation = preg_replace($patterns, $replacements, $translation); + + // Double quoting is mandatory to have new lines instead of \n strings + return sprintf(" Date: Sun, 4 Mar 2018 01:02:02 +0100 Subject: New Docker (#1813) * Draft of new Docker Based on Alpine Linux. Size ~78MB. https://github.com/FreshRSS/docker-freshrss/issues/4 https://github.com/FreshRSS/FreshRSS/issues/520 https://github.com/FreshRSS/docker-freshrss https://github.com/FreshRSS/docker-freshrss-production * Docker readme * +x execution rights prepare * Docker readme links to hub.docker.com https://hub.docker.com/r/freshrss/freshrss/ --- .dockerignore | 3 ++ Docker/Dockerfile | 22 +++++++++++ Docker/FreshRSS.Apache.conf | 27 ++++++++++++++ Docker/README.md | 91 +++++++++++++++++++++++++++++++++++++++++++++ README.fr.md | 2 + README.md | 3 +- cli/README.md | 3 ++ cli/prepare.php | 37 ++++++++++++++++++ lib/Minz/Request.php | 3 +- 9 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Docker/Dockerfile create mode 100644 Docker/FreshRSS.Apache.conf create mode 100644 Docker/README.md create mode 100755 cli/prepare.php (limited to 'cli') diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ab223517d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +*/.git +*/data +*/docs diff --git a/Docker/Dockerfile b/Docker/Dockerfile new file mode 100644 index 000000000..fc753e58d --- /dev/null +++ b/Docker/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:3.7 + +RUN apk add --no-cache \ + apache2 php7-apache2 \ + php7 php7-curl php7-gmp php7-intl php7-mbstring php7-xml php7-zip \ + php7-ctype php7-dom php7-fileinfo php7-json php7-session \ + php7-pdo_sqlite \ + php7-pdo_mysql \ + php7-pdo_pgsql + +ENV FRESHRSS_ROOT /var/www/FreshRSS +RUN mkdir -p ${FRESHRSS_ROOT} /run/apache2/ +WORKDIR ${FRESHRSS_ROOT} + +COPY . ${FRESHRSS_ROOT} +COPY ./Docker/*.Apache.conf /etc/apache2/conf.d/ + +EXPOSE 80 +CMD php -f ./cli/prepare.php > /dev/null && \ + chown -R :apache ${FRESHRSS_ROOT} && \ + chmod -R g+r ${FRESHRSS_ROOT} && chmod -R g+w ${FRESHRSS_ROOT}/data/ && \ + exec httpd -D FOREGROUND diff --git a/Docker/FreshRSS.Apache.conf b/Docker/FreshRSS.Apache.conf new file mode 100644 index 000000000..59151d749 --- /dev/null +++ b/Docker/FreshRSS.Apache.conf @@ -0,0 +1,27 @@ + + LoadModule deflate_module modules/mod_deflate.so + + + LoadModule expires_module modules/mod_expires.so + + + LoadModule headers_module modules/mod_headers.so + + + LoadModule mime_module modules/mod_mime.so + + + LoadModule rewrite_module modules/mod_rewrite.so + + +ServerName freshrss.localhost +Listen 0.0.0.0:80 +DocumentRoot /var/www/FreshRSS/p/ +ErrorLog /dev/stderr +TransferLog /dev/stdout +AllowEncodedSlashes On + + + AllowOverride AuthConfig FileInfo Indexes Limit + Require all granted + diff --git a/Docker/README.md b/Docker/README.md new file mode 100644 index 000000000..d85b9a6f0 --- /dev/null +++ b/Docker/README.md @@ -0,0 +1,91 @@ +# Deploy FreshRSS with Docker +* See also https://hub.docker.com/r/freshrss/freshrss/ + +## Install Docker + +```sh +curl -fsSL https://get.docker.com/ -o get-docker.sh +sh get-docker.sh +``` + +## Optional: Build Docker image of FreshRSS +Optional, as a *less recent* [online image](https://hub.docker.com/r/freshrss/freshrss/) can be automatically fetched during the next step (run), +but online images are not available for as many platforms as if you build yourself. + +```sh +# First time only +git clone https://github.com/FreshRSS/FreshRSS.git + +cd ./FreshRSS/ +git pull +sudo docker pull alpine:3.7 +sudo docker build --tag freshrss/freshrss -f Docker/Dockerfile . +``` + +## Run FreshRSS + +Example exposing FreshRSS on port 8080. You may have to adapt the network parameters to fit your needs. + +```sh +# You can optionally run from the directory containing the FreshRSS source code: +cd ./FreshRSS/ + +# The data will be saved on the host in `./data/` +mkdir -p ./data/ + +sudo docker run -dit --restart unless-stopped --log-opt max-size=10m \ + -v $(pwd)/data:/var/www/FreshRSS/data \ + -p 8080:80 \ + --name freshrss freshrss/freshrss +``` + +## Update + +```sh +# Rebuild an image (see build section above) or get a new online version: +sudo docker pull freshrss/freshrss +# And then +sudo docker stop freshrss +docker rename freshrss freshrss_old +# See the run section above for the full command +sudo docker run ... +# If everything is working, delete the old container +docker rm freshrss_old +``` + +## Command line + +```sh +sudo docker exec -it freshrss php ./cli/list-users.php +``` + +See the [CLI documentation](../cli/) for all the other commands. + +### Cron job to refresh feeds +Set a cron job up on your host machine, calling the `actualize_script.php` inside the FreshRSS Docker instance. + +#### Example on Debian / Ubuntu +Create `/etc/cron.d/FreshRSS` with: + +``` +7,37 * * * * root docker exec -it freshrss php ./app/actualize_script.php > /tmp/FreshRSS.log 2>&1 +``` + +## Debugging + +```sh +# See FreshRSS data (it is on the host) +cd ./data/ +# See Web server logs +sudo docker logs -f freshrss + +# Enter inside FreshRSS docker container +sudo docker exec -it freshrss sh +## See FreshRSS root inside the container +ls /var/www/FreshRSS/ +``` + +## Deployment in production + +Use a reverse proxy on your host server, such as [Træfik](https://traefik.io/) or [nginx](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/), +with HTTPS, for instance using [Let’s Encrypt](https://letsencrypt.org/). diff --git a/README.fr.md b/README.fr.md index fc99d0e4c..97ffafb56 100644 --- a/README.fr.md +++ b/README.fr.md @@ -55,6 +55,8 @@ Nous sommes une communauté amicale. 7. Avec Apache, activer [`AllowEncodedSlashes`](https://httpd.apache.org/docs/trunk/mod/core.html#allowencodedslashes) pour une meilleure compatibilité avec les clients mobiles. ## Installation automatisée +* [Docker](./Docker/) +* [![Cloudron](https://cloudron.io/img/button.svg)](https://cloudron.io/button.html?app=org.freshrss.cloudronapp) * [![DP deploy](https://raw.githubusercontent.com/DFabric/DPlatform-ShellCore/gh-pages/img/deploy.png)](https://dfabric.github.io/DPlatform-ShellCore) * [YunoHost](https://github.com/YunoHost-Apps/freshrss_ynh) diff --git a/README.md b/README.md index 23358d98e..8858dd12d 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,8 @@ We are a friendly community. More information about installation and server configuration can be found in [our documentation](https://freshrss.github.io/FreshRSS/en/admins/02_Installation.html). ## Automated install -* [![Install on Cloudron](https://cloudron.io/img/button.svg)](https://cloudron.io/button.html?app=org.freshrss.cloudronapp) +* [Docker](./Docker/) +* [![Cloudron](https://cloudron.io/img/button.svg)](https://cloudron.io/button.html?app=org.freshrss.cloudronapp) * [![DP deploy](https://raw.githubusercontent.com/DFabric/DPlatform-ShellCore/gh-pages/img/deploy.png)](https://dfabric.github.io/DPlatform-ShellCore) * [YunoHost](https://github.com/YunoHost-Apps/freshrss_ynh) diff --git a/cli/README.md b/cli/README.md index a496aab58..d531b8c3d 100644 --- a/cli/README.md +++ b/cli/README.md @@ -32,6 +32,9 @@ Options in parenthesis are optional. ```sh cd /usr/share/FreshRSS +./cli/prepare.php +# Ensure the needed directories in ./data/ + ./cli/do-install.php --default_user admin ( --auth_type form --environment production --base_url https://rss.example.net/ --language en --title FreshRSS --allow_anonymous --api_enabled --db-type mysql --db-host localhost:3306 --db-user freshrss --db-password dbPassword123 --db-base freshrss --db-prefix freshrss ) # --auth_type can be: 'form' (default), 'http_auth' (using the Web server access control), 'none' (dangerous) # --db-type can be: 'sqlite' (default), 'mysql' (MySQL or MariaDB), 'pgsql' (PostgreSQL) diff --git a/cli/prepare.php b/cli/prepare.php new file mode 100755 index 000000000..2db2da555 --- /dev/null +++ b/cli/prepare.php @@ -0,0 +1,37 @@ +#!/usr/bin/php + Date: Sun, 4 Mar 2018 14:41:40 +0100 Subject: Add new tools to manipulate translations (#1818) I've added a tool to add a new translation for a specific key and language. I've added a tool to format the i18n files. This is one of the steps to improve the translation process. --- cli/i18n/I18nData.php | 24 +++++++++++++++++++++++- cli/i18n/I18nFile.php | 2 +- cli/manipulate.translation.php | 19 +++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) (limited to 'cli') diff --git a/cli/i18n/I18nData.php b/cli/i18n/I18nData.php index cd8ba0765..b8f958288 100644 --- a/cli/i18n/I18nData.php +++ b/cli/i18n/I18nData.php @@ -32,6 +32,7 @@ class I18nData { * Add a new language. It's a copy of the reference language. * * @param string $language + * @throws Exception */ public function addLanguage($language) { if (array_key_exists($language, $this->data)) { @@ -45,6 +46,7 @@ class I18nData { * * @param string $key * @param string $value + * @throws Exception */ public function addKey($key, $value) { if (array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { @@ -53,10 +55,29 @@ class I18nData { $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)][$key] = $value; } + /** + * Add a value for a key for the selected language. + * + * @param string $key + * @param string $value + * @param string $language + * @throws Exception + */ + public function addValue($key, $value, $language) { + if (!in_array($language, $this->getAvailableLanguages())) { + throw new Exception('The selected language does not exist.'); + } + if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { + throw new Exception('The selected key does not exist for the selected language.'); + } + $this->data[$language][$this->getFilenamePrefix($key)][$key] = $value; + } + /** * Duplicate a key from the reference language to all other languages * * @param string $key + * @throws Exception */ public function duplicateKey($key) { if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { @@ -68,7 +89,7 @@ class I18nData { continue; } if (array_key_exists($key, $this->data[$language][$this->getFilenamePrefix($key)])) { - throw new Exception(sprintf('The selected key already exist in %s.', $language)); + continue; } $this->data[$language][$this->getFilenamePrefix($key)][$key] = $value; } @@ -78,6 +99,7 @@ class I18nData { * Remove a key in all languages * * @param string $key + * @throws Exception */ public function removeKey($key) { if (!array_key_exists($key, $this->data[static::REFERENCE_LANGUAGE][$this->getFilenamePrefix($key)])) { diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.php index 627f6f580..a07efdf88 100644 --- a/cli/i18n/I18nFile.php +++ b/cli/i18n/I18nFile.php @@ -113,7 +113,7 @@ class i18nFile { $translation = preg_replace($patterns, $replacements, $translation); // Double quoting is mandatory to have new lines instead of \n strings - return sprintf("addKey($argv[2], $argv[3]); break; + case 'add_value': + if (4 === $argc) { + help(); + } + $i18nData->addValue($argv[2], $argv[3], $argv[4]); + break; case 'duplicate_key' : $i18nData->duplicateKey($argv[2]); break; case 'delete_key' : $i18nData->removeKey($argv[2]); break; + case 'format' : + $i18nFile->dump($i18nData); + break; default : help(); } @@ -48,7 +57,7 @@ NAME %s SYNOPSIS - php %s [OPTION] [OPERATION] [KEY] [VALUE] + php %s [OPTION] [OPERATION] [KEY] [VALUE] [LANGUAGE] DESCRIPTION Manipulate translation files. Available operations are @@ -64,6 +73,10 @@ OPERATION add_key add a new key in the referential. This operation needs a KEY and a VALUE. + add_value + add a value in the referential. This operation needs a KEY, a + VALUE, and a LANGUAGE. + duplicate_key duplicate a referential key in other languages. This operation needs only a KEY. @@ -72,6 +85,8 @@ OPERATION delete a referential key from all languages. This operation needs only a KEY. + format format i18n files. + HELP; $file = str_replace(__DIR__ . '/', '', __FILE__); echo sprintf($help, $file, $file); -- cgit v1.2.3