From b15f36c36c5695dadbc5afdbe4907b18db0a9cb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Th=C3=A9r=C3=A8se=20Godefroy?= <godef.th@free.fr> Date: Sun, 15 Aug 2021 12:15:05 +0200 Subject: [PATCH] Add tools to synchronize enc-live with enc. --- copy-enc-to-live | 54 +++++++++++++++++++++++++++++++++++++++++++++ lang-picker-source | 16 ++++++++++++++ replace-lang-picker | 41 ++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100755 copy-enc-to-live create mode 100644 lang-picker-source create mode 100755 replace-lang-picker diff --git a/copy-enc-to-live b/copy-enc-to-live new file mode 100755 index 0000000..8f4a2c9 --- /dev/null +++ b/copy-enc-to-live @@ -0,0 +1,54 @@ +#! /bin/bash + +# Copy Email Self-Defense translations locally from enc to enc-live. +# and update the language pickers. +# The two repos are assumed to have the same parent directory. +# The script is called from the root of enc-live: +# copy-enc-to-live LANG + +# ***** Check that lang-picker-source is up to date. ***** + +set -e + +lang=$1 +pages='confirmation.html index.html infographic.html next_steps.html workshops.html' + +test -n "$lang" || (echo " !!! Please enter a language code as argument."; + exit 1) + +# The files we need are on the master branch of enc. +cd ../enc +git co master +# Get the ID of the last commit on this branch for future reference, and +# truncate it to 7 digits. +commit=$(git rev-parse HEAD | cut -b -7) + +# Go back to enc-live. +cd ../enc-live +# Create the LANG directory if it doesn't exist. +mkdir -p $lang + +# Take one page at a time. +for p in $pages; do + echo $lang/$p + # If it exists in enc, + if [ -f ../enc/$lang/$p ]; then + # copy it to enc-live. + cp ../enc/$lang/$p $lang/ + # If not... + else + # say so, + echo " !!! $lang/$p doesn't exist" + # restore enc-live to its original state, + git reset --hard HEAD + # and quit. + exit 1 + fi +done + +# Add and commit the changes. +git add $lang +# Refer to the enc commit ID in the enc-live commit message. +git commit -m "$lang: synchronize with enc $commit." + +replace-lang-picker diff --git a/lang-picker-source b/lang-picker-source new file mode 100644 index 0000000..59fab62 --- /dev/null +++ b/lang-picker-source @@ -0,0 +1,16 @@ +<li><a href="/en">English - v5.0</a></li> +<li><a href="/es">español - v5.0</a></li> +<li><a href="/fr">français - v5.0</a></li> +<li><a href="/tr">Türkçe - v5.0</a></li> +<!--<li><a href="/cs">ÄeÅ¡tina - v4.0</a></li> +<li><a href="/de">Deutsch - v4.0</a></li> +<li><a href="/el">ελληνικά - v3.0</a></li> +<li><a href="/fa">ÙØ§Ø±Ø³Û - v4.0</a></li> +<li><a href="/it">italiano - v3.0</a></li> +<li><a href="/ja">æ¥æ¬èª - v4.0</a></li> +<li><a href="/pt-br">português do Brasil - v3.0</a></li> +<li><a href="/ro">românÄ - v3.0</a></li> +<li><a href="/ru">ÑÑÑÑкий - v4.0</a></li> +<li><a href="/sq">Shqip - v4.0</a></li> +<li><a href="/sv">svenska - v4.0</a></li> +<li><a href="/zh-hans">ç®ä½ä¸æ - v4.0</a></li>--> diff --git a/replace-lang-picker b/replace-lang-picker new file mode 100755 index 0000000..4b9b551 --- /dev/null +++ b/replace-lang-picker @@ -0,0 +1,41 @@ +#!/bin/bash + +# Replace the language picker site-wide, using a common source file: +# "lang-picker-source". The script is called from the root of enc-live. +# It doesn't take an argument. + +set -e +set -o pipefail + +head=$(mktemp -t rt.XXXXXX) || exit 1 +picker=$(mktemp -t rt.XXXXXX) || exit 1 +tail=$(mktemp -t rt.XXXXXX) || exit 1 +trap 'rm -f "$head" "$picker" "$tail"' EXIT + +# List all HTML files with a language picker and take them one by one. +# The regex will select index and workshops. +find . -regex "\./.*/[iw][no][dr].*\.html" -not -path "./missing/*" | +sort | sed 's,^\./,,' | while read f; do + # Extract the language from the file name. + lang=${f%%/*} + # Make sure the page is correctly formatted. + if grep -q '<ul id="languages" class="os">' $f && + grep -q '<li><strong><a href=.*Translation_Guide">' $f; then + # Add the 'current' class to the relevant item of lang-picker-source. + sed "s,<li><a href=\"/$lang\">,<li><a class=\"current\" href=\"/$lang\">," \ + lang-picker-source > $picker + # Extract what's before the language picker... + sed -n '1,/<ul id="languages" class="os">/p' $f > $head + # and what follows it. + sed -n '/<li><strong><a href=.*Translation_Guide">/,$p' $f > $tail + # Assemble. + cat $head $picker $tail > $f + else + echo " !!! Unable to replace the language picker in $f." + exit 1 + fi +done + +# Commit the changes. +git add */index.html */workshops.html +git commit -m "index & workshops: update the language picker." -- 2.25.1