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 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()