From 737bf68f9502112d94826fde51ce9b376d650200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=28=D0=A5?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D1=8B=D1=87=D0=AA=29=20=D0=A5=D1=80=D0=B0?= =?UTF-8?q?=D0=BC=D0=BE=D0=B2?= Date: Tue, 26 Aug 2025 22:43:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20i18n-precommit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 5 ++-- scripts/i18n-precommit.sh | 63 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100755 scripts/i18n-precommit.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 87b4e81..1c3eb76 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,6 +37,7 @@ repos: - id: i18n name: Update i18n - entry: make i18n + entry: bash scripts/i18n-precommit.sh language: system - pass_filenames: false \ No newline at end of file + pass_filenames: false + always_run: true \ No newline at end of file diff --git a/scripts/i18n-precommit.sh b/scripts/i18n-precommit.sh new file mode 100755 index 0000000..0b76d38 --- /dev/null +++ b/scripts/i18n-precommit.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# ALR - Any Linux Repository +# Copyright (C) 2025 The ALR Authors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Wrapper script for i18n that automatically stages changed files for pre-commit + +set -e + +# Сохраняем состояние файлов до выполнения i18n +TRANSLATION_FILES=( + "internal/translations/default.pot" + "internal/translations/po/ru/default.po" + "assets/i18n-ru-badge.svg" +) + +# Создаем временные файлы для сравнения +TEMP_DIR=$(mktemp -d) +for file in "${TRANSLATION_FILES[@]}"; do + if [[ -f "$file" ]]; then + cp "$file" "$TEMP_DIR/$(basename "$file")" + fi +done + +# Выполняем обновление переводов +make i18n + +# Проверяем какие файлы изменились и добавляем их в staging area +CHANGED_FILES=() +for file in "${TRANSLATION_FILES[@]}"; do + if [[ -f "$file" ]]; then + if [[ ! -f "$TEMP_DIR/$(basename "$file")" ]] || ! cmp -s "$file" "$TEMP_DIR/$(basename "$file")"; then + CHANGED_FILES+=("$file") + fi + fi +done + +# Добавляем измененные файлы в git staging area +if [[ ${#CHANGED_FILES[@]} -gt 0 ]]; then + echo "Auto-staging changed translation files:" + for file in "${CHANGED_FILES[@]}"; do + echo " - $file" + git add "$file" + done +fi + +# Очищаем временные файлы +rm -rf "$TEMP_DIR" + +# Выход с кодом 0 (успех) даже если файлы были изменены +exit 0 \ No newline at end of file