From b15f36c36c5695dadbc5afdbe4907b18db0a9cb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Th=C3=A9r=C3=A8se=20Godefroy?= 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 @@ +
  • English - v5.0
  • +
  • español - v5.0
  • +
  • français - v5.0
  • +
  • Türkçe - v5.0
  • + 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 '