From c96d8eae59407e163a63ede002d8e949373aa91f Mon Sep 17 00:00:00 2001 From: rockleona Date: Wed, 21 Feb 2024 13:32:42 +0800 Subject: [PATCH 1/2] chore: move scripts to makefile, except from_cn --- .scripts/requirements.txt | 4 ++++ Makefile | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .scripts/requirements.txt diff --git a/.scripts/requirements.txt b/.scripts/requirements.txt new file mode 100644 index 0000000000..ba1a5590c4 --- /dev/null +++ b/.scripts/requirements.txt @@ -0,0 +1,4 @@ +polib==1.1.1 +googletrans==3.1.0a0 +translate-toolkit==3.8.1 +requests==2.31.0 \ No newline at end of file diff --git a/Makefile b/Makefile index c778061656..643e323cbd 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,7 @@ SPHINX_CONF := $(CPYTHON_CLONE)/Doc/conf.py LANGUAGE := zh_TW LC_MESSAGES := $(CPYTHON_CLONE)/Doc/locales/$(LANGUAGE)/LC_MESSAGES VENV := ~/.venvs/python-docs-i18n/ +VENV_FOR_SCRIPT := ~/.venvs/python-docs-zhtw-script/ PYTHON := $(shell which python3) MODE := autobuild-dev-html BRANCH := $(or $(VERSION), $(shell git describe --contains --all HEAD)) @@ -75,6 +76,33 @@ $(VENV)/bin/sphinx-lint: $(VENV)/bin/activate $(VENV)/bin/blurb: $(VENV)/bin/activate . $(VENV)/bin/activate; python3 -m pip install blurb +$(VENV_FOR_SCRIPT)/bin/activate: + mkdir -p $(VENV_FOR_SCRIPT) + $(PYTHON) -m venv $(VENV_FOR_SCRIPT) + . $(VENV_FOR_SCRIPT)/bin/activate; python3 -m pip install -r .scripts/requirements.txt + +.PHONY: summarize_progress +summarize_progress: $(VENV_FOR_SCRIPT)/bin/activate + cd .scripts && \ + . $(VENV_FOR_SCRIPT)/bin/activate; \ + python3 summarize_progress/main.py + +.PHONY: google_translate +google_translate: $(VENV_FOR_SCRIPT)/bin/activate + if [ -z $(filter-out $@,$(MAKECMDGOALS)) ]; then \ + echo "Please provide a file argument."; \ + exit 1; \ + fi + + @$(eval __target=$(filter-out $@,$(MAKECMDGOALS))) + @$(eval __filepath=$(addprefix ../,$(__target))) + @$(eval __temp_po_file=tmp.po) + + cd .scripts && \ + . $(VENV_FOR_SCRIPT)/bin/activate; \ + python3 google_translate/main.py $(__filepath) > $(__temp_po_file) ; pomerge -t $(__filepath) -i $(__temp_po_file) -o $(__filepath); rm "$(__temp_po_file)" + exit 0 + .PHONY: upgrade_venv upgrade_venv: $(VENV)/bin/activate ## Upgrade the venv that compiles the doc From b8254ce2f1f2cca864a876889e56d803b071d322 Mon Sep 17 00:00:00 2001 From: rockleona Date: Wed, 21 Feb 2024 15:42:32 +0800 Subject: [PATCH 2/2] chore: add file check rules --- Makefile | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 643e323cbd..d7286e45d9 100644 --- a/Makefile +++ b/Makefile @@ -89,18 +89,34 @@ summarize_progress: $(VENV_FOR_SCRIPT)/bin/activate .PHONY: google_translate google_translate: $(VENV_FOR_SCRIPT)/bin/activate - if [ -z $(filter-out $@,$(MAKECMDGOALS)) ]; then \ + + @$(eval _target=$(filter-out $@, $(MAKECMDGOALS))) + @if [ -z $(_target) ]; then \ echo "Please provide a file argument."; \ exit 1; \ fi - @$(eval __target=$(filter-out $@,$(MAKECMDGOALS))) - @$(eval __filepath=$(addprefix ../,$(__target))) - @$(eval __temp_po_file=tmp.po) + + @if [ "$(suffix $(_target))" != ".po" ]; then \ + echo "Incorrect file extension. Only '.po' files are allowed."; \ + exit 1; \ + else \ + _target=$(addsuffix ,po,$(_target)); \ + fi + + @if [ ! -f "$(_target)" ]; then \ + echo "File '$(filter-out $@, $(_target))' does not exist."; \ + exit 1; \ + fi + + @$(eval _tmp_po_file=tmp.po) + @$(eval _file_path=$(addprefix ../, $(_target))) cd .scripts && \ . $(VENV_FOR_SCRIPT)/bin/activate; \ - python3 google_translate/main.py $(__filepath) > $(__temp_po_file) ; pomerge -t $(__filepath) -i $(__temp_po_file) -o $(__filepath); rm "$(__temp_po_file)" + python3 google_translate/main.py $(_file_path) > $(_tmp_po_file) ; \ + pomerge -t $(_file_path) -i $(_tmp_po_file) -o $(_file_path) ; \ + # rm $(_tmp_po_file) exit 0 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy