Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF'
python scripts/list_missing_entries.py --github $CHANGED_PO_FILES
echo EOF
} >> "$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
55 changes: 55 additions & 0 deletions scripts/list_missing_entries.py
Original file line number Diff line number Diff line change
@@ -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()