From 893a598ef1b97263c9106bd5ab1834bc1a030cf0 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Tue, 24 Oct 2023 21:13:51 +0800 Subject: [PATCH 1/6] =?UTF-8?q?A=C3=B1ade=20nuevo=20script=20que=20indica?= =?UTF-8?q?=20entradas=20faltantes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit El script está diseñado para ser usado ya sea como un hook de pre-commit, o (principalmente) dentro de una nuevo paso del GitHub action que revisa PRs, de tal modo que se añada y actualice automáticamente un comentario en el PR indicando si todas las entradas del archivo siendo traducido han sido completadas o no. Signed-off-by: Rodrigo Tobar --- scripts/list_missing_entries.py | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/list_missing_entries.py diff --git a/scripts/list_missing_entries.py b/scripts/list_missing_entries.py new file mode 100644 index 0000000000..4c51b37a63 --- /dev/null +++ b/scripts/list_missing_entries.py @@ -0,0 +1,55 @@ +import argparse +import dataclasses +import enum +import glob +import itertools +import os + +import polib +import tabulate + + +class MissingReason(enum.StrEnum): + FUZZY = "fuzzy" + UNTRANSLATED = "untranslated" + + @staticmethod + def from_poentry(poentry: polib.POEntry): + if poentry.fuzzy: + return MissingReason.FUZZY + assert not poentry.translated() + return MissingReason.UNTRANSLATED + +@dataclasses.dataclass +class MissingEntry: + reason: MissingReason + file: str + line: int + + @staticmethod + def from_poentry(pofilename: str, poentry: polib.POEntry) -> "MissingEntry": + return MissingEntry(MissingReason.from_poentry(poentry), pofilename, poentry.linenum) + + +def find_missing_entries(filename: str) -> list[MissingEntry]: + po = polib.pofile(filename) + fuzzy = po.fuzzy_entries() + untranslated = po.untranslated_entries() + return [MissingEntry.from_poentry(filename, entry) for entry in fuzzy + untranslated] + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("files", nargs="+") + parser.add_argument("-g", "--github-mode", help="Produce output as a GitHub comment", action='store_true') + opts = parser.parse_args() + missing_entries = list(itertools.chain.from_iterable(map(find_missing_entries, opts.files))) + if not missing_entries: + print(f"All entries translated, horray!{' :tada:' if opts.github_mode else ''}") + else: + missing_entries.sort(key = lambda entry: (entry.file, entry.line)) + print("Entries missing translation, details follow:\n") + print(tabulate.tabulate(missing_entries,headers=["Reason", "File", "Line"], tablefmt="github")) + + +if __name__ == "__main__": + main() From e118c1b754b0fbfb8eb9d76b2342cd04c27e9729 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Tue, 24 Oct 2023 21:29:20 +0800 Subject: [PATCH 2/6] =?UTF-8?q?A=C3=B1ade=20comentarios=20a=20PRs=20con=20?= =?UTF-8?q?entradas=20faltantes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-comment.yml | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/pr-comment.yml diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml new file mode 100644 index 0000000000..7be6faccd1 --- /dev/null +++ b/.github/workflows/pr-comment.yml @@ -0,0 +1,45 @@ +name: Agrega comentario a PR + +on: + pull_request_target: + +jobs: + pr-comment: + name: Entradas sin traducción + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + persist-credentials: false + - name: Preparar Python v3.11 + uses: actions/setup-python@v4 + with: + python-version: "3.11" + cache: "pip" + - name: Instalar dependencias + run: | + python -m pip install -r requirements.txt + - name: Obtiene lista de archivos con cambios + id: changed-files + uses: tj-actions/changed-files@v39 + with: + files: | + **/*.po + - name: Calcular entradas faltantes + if: steps.changed-files.outputs.any_changed == 'true' + id: create-pr-comment + env: + CHANGED_PO_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + run: | + { + echo 'comment<> "$GITHUB_OUTPUT" + - name: Agregar comentario con entradas faltantes + if: steps.changed-files.outputs.any_changed == 'true' + uses: thollander/actions-comment-pull-request@v2 + with: + message: ${{ steps.create-pr-comment.outputs.comment }} + comment_tag: missing-entries From 49aab95a450edd7f0c157d2d72730e73b2b6a20e Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Wed, 1 Nov 2023 20:10:46 +0800 Subject: [PATCH 3/6] dummy; --- library/filecmp.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/filecmp.po b/library/filecmp.po index 1390199a6b..b4a7671051 100644 --- a/library/filecmp.po +++ b/library/filecmp.po @@ -14,7 +14,7 @@ msgstr "" "PO-Revision-Date: 2020-09-27 12:59-0400\n" "Last-Translator: Enrique Giménez \n" "Language: es_PY\n" -"Language-Team: Enrique Giménez\n" +"Language-Team: Enrique Giménez y yo\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" From 5cc9fca73dcf16730a2b1f649da055088867501d Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Wed, 1 Nov 2023 20:57:26 +0800 Subject: [PATCH 4/6] falta-uno-solo --- library/filecmp.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/filecmp.po b/library/filecmp.po index b4a7671051..6321d78a2d 100644 --- a/library/filecmp.po +++ b/library/filecmp.po @@ -204,7 +204,7 @@ msgid "" "lazily, so there is no speed penalty if only those attributes which are " "lightweight to compute are used." msgstr "" -"Note que vía los hooks :meth:`__getattr__`, todos los atributos son " +"Note que vía los hooks :meth:`~object.__getattr__`, todos los atributos son " "perezosamente computados, así que no hay penalización de velocidad si sólo " "esos atributos que son ligeros de computar son utilizados." From 879f63297b7e8b9334f1840d38de50c33ef1c3dc Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Wed, 1 Nov 2023 21:00:03 +0800 Subject: [PATCH 5/6] remove-fuzzy --- library/filecmp.po | 1 - 1 file changed, 1 deletion(-) diff --git a/library/filecmp.po b/library/filecmp.po index 6321d78a2d..2f86a5d71c 100644 --- a/library/filecmp.po +++ b/library/filecmp.po @@ -198,7 +198,6 @@ msgstr "" "árboles de directorio que están siendo comparados." #: ../Doc/library/filecmp.rst:103 -#, fuzzy msgid "" "Note that via :meth:`~object.__getattr__` hooks, all attributes are computed " "lazily, so there is no speed penalty if only those attributes which are " From c98249fb31d9c5611e4fa5c8b8eff8baa6d62f82 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Wed, 1 Nov 2023 21:07:41 +0800 Subject: [PATCH 6/6] no more fuzzies --- library/filecmp.po | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/filecmp.po b/library/filecmp.po index 2f86a5d71c..c2cfea385a 100644 --- a/library/filecmp.po +++ b/library/filecmp.po @@ -145,7 +145,6 @@ msgid "The :class:`dircmp` class" msgstr "La clase :class:`dircmp`" #: ../Doc/library/filecmp.rst:75 -#, fuzzy msgid "" "Construct a new directory comparison object, to compare the directories *a* " "and *b*. *ignore* is a list of names to ignore, and defaults to :const:" @@ -154,7 +153,7 @@ msgid "" msgstr "" "Construye un nuevo objeto de comparación de directorio, para comparar los " "directorios *a* y *b*. *ignore* es una lista de nombres a ignorar, y " -"predetermina a :attr:`filecmp.DEFAULT_IGNORES`. *hide* es una lista de " +"predetermina a :const:`filecmp.DEFAULT_IGNORES`. *hide* es una lista de " "nombres a ocultar, y predetermina a ``[os.curdir, os.pardir]``." #: ../Doc/library/filecmp.rst:80