| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,8 +44,10 @@ jobs: | |||
| 44 | 44 | - name: Setup problem matcher | |
| 45 | 45 | uses: rffontenelle/sphinx-lint-problem-matcher@v1.0.0 | |
| 46 | 46 | ||
| 47 | + # we have to disable trailing-whitespace on sphinx-lint for now | ||
| 48 | + # see github.com/sphinx-contrib/sphinx-lint/issues/120 | ||
| 47 | 49 | - name: Run sphinx-lint | |
| 48 | - run: sphinx-lint | ||
| 50 | + run: sphinx-lint --disable trailing-whitespace | ||
| 49 | 51 | working-directory: Doc/locales/fa/LC_MESSAGES | |
| 50 | 52 | ||
| 51 | 53 | - name: Check PO file validity | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,7 +118,7 @@ line-length: | |||
| 118 | 118 | .PHONY: sphinx-lint | |
| 119 | 119 | sphinx-lint: | |
| 120 | 120 | @echo "Checking all files using sphinx-lint..." | |
| 121 | - @sphinx-lint --enable all --disable line-too-long *.po */*.po | ||
| 121 | + @sphinx-lint --enable all --disable line-too-long --disable trailing-whitespace *.po */*.po | ||
| 122 | 122 | ||
| 123 | 123 | $(POSPELL_TMP_DIR)/%.po.out: %.po dict | |
| 124 | 124 | @echo "Pospell checking $<..." | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,125 @@ | |||
| 1 | + # #!/usr/bin/env python3 | ||
| 2 | + # """ | ||
| 3 | + # Remove the `#, fuzzy` marker that precedes the header entry | ||
| 4 | + # (msgid "" / msgstr "") in .po files. | ||
| 5 | + | ||
| 6 | + # Usage: | ||
| 7 | + # python remove_fuzzy_header.py path/to/dir_or_files... | ||
| 8 | + # """ | ||
| 9 | + # import sys | ||
| 10 | + # import re | ||
| 11 | + # from pathlib import Path | ||
| 12 | + | ||
| 13 | + # # Matches "#, fuzzy\n" immediately followed by the empty msgid/msgstr header | ||
| 14 | + # PATTERN = re.compile( | ||
| 15 | + # r'^#, fuzzy\n(?=msgid ""\nmsgstr "")', | ||
| 16 | + # re.MULTILINE | ||
| 17 | + # ) | ||
| 18 | + | ||
| 19 | + # def process_file(path: Path) -> bool: | ||
| 20 | + # text = path.read_text(encoding="utf-8") | ||
| 21 | + # new_text, count = PATTERN.subn("", text) | ||
| 22 | + # if count: | ||
| 23 | + # path.write_text(new_text, encoding="utf-8") | ||
| 24 | + # print(f"Updated: {path} ({count} removal)") | ||
| 25 | + # return True | ||
| 26 | + # return False | ||
| 27 | + | ||
| 28 | + # def main(paths): | ||
| 29 | + # files = [] | ||
| 30 | + # for p in paths: | ||
| 31 | + # p = Path(p) | ||
| 32 | + # if p.is_dir(): | ||
| 33 | + # files.extend(p.rglob("*.po")) | ||
| 34 | + # elif p.suffix == ".po": | ||
| 35 | + # files.append(p) | ||
| 36 | + | ||
| 37 | + # if not files: | ||
| 38 | + # print("No .po files found.") | ||
| 39 | + # return | ||
| 40 | + | ||
| 41 | + # changed = 0 | ||
| 42 | + # for f in files: | ||
| 43 | + # if process_file(f): | ||
| 44 | + # changed += 1 | ||
| 45 | + | ||
| 46 | + # print(f"\nDone. {changed}/{len(files)} file(s) modified.") | ||
| 47 | + | ||
| 48 | + # if __name__ == "__main__": | ||
| 49 | + # if len(sys.argv) < 2: | ||
| 50 | + # print("Usage: python remove_fuzzy_header.py <dir_or_files...>") | ||
| 51 | + # sys.exit(1) | ||
| 52 | + # main(sys.argv[1:]) | ||
| 53 | + | ||
| 54 | + #!/usr/bin/env python3 | ||
| 55 | + """ | ||
| 56 | + Fix .po headers where the Last-Translator line is missing its trailing | ||
| 57 | + \\n before the closing quote, causing it to swallow the next header | ||
| 58 | + line (e.g. Language-Team) into the same string. | ||
| 59 | + | ||
| 60 | + Broken: | ||
| 61 | + "Last-Translator: NAME <EMAIL>, YEAR" | ||
| 62 | + "Language-Team: ...\\n" | ||
| 63 | + | ||
| 64 | + Fixed: | ||
| 65 | + "Last-Translator: NAME <EMAIL>, YEAR\\n" | ||
| 66 | + "Language-Team: ...\\n" | ||
| 67 | + | ||
| 68 | + Usage: | ||
| 69 | + python fix_last_translator_newline.py --dry-run path/to/dir | ||
| 70 | + python fix_last_translator_newline.py path/to/dir | ||
| 71 | + """ | ||
| 72 | + import re | ||
| 73 | + import argparse | ||
| 74 | + from pathlib import Path | ||
| 75 | + | ||
| 76 | + # Matches a Last-Translator line whose value ends directly in a | ||
| 77 | + # closing quote with NO \n escape before it. | ||
| 78 | + PATTERN = re.compile( | ||
| 79 | + r'^"Last-Translator: ([^"\n]*?)"\n(?!")', # lookahead not required but harmless | ||
| 80 | + re.MULTILINE, | ||
| 81 | + ) | ||
| 82 | + # More precise: only match if it does NOT already end with \n before the quote | ||
| 83 | + BROKEN = re.compile(r'^"Last-Translator: ([^"\n]*[^\\n])"\n', re.MULTILINE) | ||
| 84 | + | ||
| 85 | + | ||
| 86 | + def fix_text(text: str): | ||
| 87 | + def repl(m): | ||
| 88 | + value = m.group(1) | ||
| 89 | + return f'"Last-Translator: {value}\\n"\n' | ||
| 90 | + | ||
| 91 | + new_text, count = BROKEN.subn(repl, text) | ||
| 92 | + return new_text, count | ||
| 93 | + | ||
| 94 | + | ||
| 95 | + def main(): | ||
| 96 | + parser = argparse.ArgumentParser() | ||
| 97 | + parser.add_argument("paths", nargs="+") | ||
| 98 | + parser.add_argument("--dry-run", action="store_true") | ||
| 99 | + args = parser.parse_args() | ||
| 100 | + | ||
| 101 | + files = [] | ||
| 102 | + for p in args.paths: | ||
| 103 | + p = Path(p) | ||
| 104 | + if p.is_dir(): | ||
| 105 | + files.extend(sorted(p.rglob("*.po"))) | ||
| 106 | + elif p.suffix == ".po": | ||
| 107 | + files.append(p) | ||
| 108 | + | ||
| 109 | + changed = 0 | ||
| 110 | + for f in files: | ||
| 111 | + if ".git" in f.parts: | ||
| 112 | + continue | ||
| 113 | + text = f.read_text(encoding="utf-8") | ||
| 114 | + new_text, count = fix_text(text) | ||
| 115 | + if count: | ||
| 116 | + print(f"{'Would fix' if args.dry_run else 'Fixed'}: {f} ({count} line(s))") | ||
| 117 | + if not args.dry_run: | ||
| 118 | + f.write_text(new_text, encoding="utf-8") | ||
| 119 | + changed += 1 | ||
| 120 | + | ||
| 121 | + print(f"\nDone. {changed} file(s) {'would be' if args.dry_run else 'were'} fixed.") | ||
| 122 | + | ||
| 123 | + | ||
| 124 | + if __name__ == "__main__": | ||
| 125 | + main() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments