🌐 feat(i18n): overhaul translation system & add languages (#145)

Revamp the existing translation system, simplifying
management and adding several new languages. The new system reads from
TOML files in the `/i18n` directory and improves template structures.
It also enhances customisation options and robustness by providing
fallbacks and modularity.

- Implement a new, streamlined translation macro.
- Load translations from `/i18n` TOML files.
- Remove redundant configuration requirements.
- Refactor templates to align with new i18n system.
- Add support for Hindi, Japanese, Russian, Portuguese, Chinese,
  Italian, German, Ukranian, Korean, and French languages.
- Credit Thomas Weitzel (@thomasweitzel) for inspiration.
This commit is contained in:
Óscar
2023-09-12 18:58:58 +02:00
committed by GitHub
parent 327545f2d5
commit 32a2d5094b
46 changed files with 1534 additions and 483 deletions

View File

@@ -262,40 +262,3 @@ if git diff --cached --name-only | grep -q "config.toml"; then
# Add the generated subset.css file to the commit.
git add static/custom_subset.css
fi
################################################################################
# Update the README if the line numbers for the language section have changed. #
################################################################################
# File paths and names.
config_file="config.toml"
config_readme="README.md"
# Ensure the required files are present.
[ ! -f "$config_file" ] && error_exit "$config_file not found!"
[ ! -f "$config_readme" ] && error_exit "$config_readme not found!"
# Determine the line numbers for relevant sections in config.toml.
lang_start_line=$(grep -n "^\[languages.es\]$" "$config_file" | cut -d: -f1)
extra_start_line=$(grep -n "^\[extra\]$" "$config_file" | cut -d: -f1)
lang_end_line=$((extra_start_line - 2))
# Extract currently documented line numbers from README.
documented_lines=$(grep -o 'https://github.com/welpo/tabi/blob/main/config.toml#L[0-9]*-L[0-9]*' "$config_readme" | grep -o 'L[0-9]*-L[0-9]*')
doc_start_line=$(echo "$documented_lines" | cut -d'-' -f1 | tr -d 'L')
doc_end_line=$(echo "$documented_lines" | cut -d'-' -f2 | tr -d 'L')
# Ensure that the variables are set and are numbers.
if [[ ! $lang_start_line =~ ^[0-9]+$ ]] || [[ ! $doc_start_line =~ ^[0-9]+$ ]] || [[ ! $lang_end_line =~ ^[0-9]+$ ]] || [[ ! $doc_end_line =~ ^[0-9]+$ ]]; then
error_exit "Line number variables are not set correctly."
fi
# Update the README if there's a discrepancy in the line numbers.
if [ "$lang_start_line" -ne "$doc_start_line" ] || [ "$lang_end_line" -ne "$doc_end_line" ]; then
if ! perl -pi -e "s|https://github.com/welpo/tabi/blob/main/config.toml#L[0-9]*-L[0-9]*|https://github.com/welpo/tabi/blob/main/config.toml#L$lang_start_line-L$lang_end_line|g" "$config_readme"; then
error_exit "Perl processing failed for $config_readme"
fi
# Add updated README to commit.
git add "$config_readme"
fi