Skip to content

Commit

Permalink
Reorganize .po linters for extensibility, similarity to other checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Aug 29, 2024
1 parent 098d468 commit db5312f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .ci/linters/po/incomplete_translation_linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
incomplete_translation_linter <- function(po_file) {
res = system2("msgfmt", c("--statistics", po_file, "-o", tempfile()), stdout=TRUE, stderr=TRUE)
if (any(grepl("untranslated message|fuzzy translation", res))) {
cat(sprintf("In %s, found incomplete translations:\n%s\n", po_file, paste(res, collapse="\n")))
stop("Please fix.")
}
}
7 changes: 7 additions & 0 deletions .ci/linters/po/tools_check_linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tools_check_linter = function(po_file) {
res = tools::checkPoFile(po_file, strictPlural=TRUE)
if (NROW(res)) {
print(res)
stop("Fix the above .po file issues.")
}
}
4 changes: 4 additions & 0 deletions .ci/linters/po/utf8_linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
utf8_linter <- function(po_file) {
if (!any(grepl("charset=UTF-8", readLines(po_file), fixed=TRUE)))
stop("In ", po_file, ", please use charset=UTF-8.")
}
18 changes: 4 additions & 14 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,11 @@ jobs:
- uses: r-lib/actions/setup-r@v2
- name: Check translations
run: |
setwd("po")
for (po_file in list.files(pattern = "[.]po$")) {
res = tools::checkPoFile(po_file, strictPlural=TRUE)
if (NROW(res)) { print(res); stop("Fix the above .po file issues.") }
if (!any(grepl("charset=UTF-8", readLines(po_file), fixed=TRUE)))
stop("In ", po_file, ", please use charset=UTF-8.")
res = system2("msgfmt", c("--statistics", po_file, "-o", tempfile()), stdout=TRUE, stderr=TRUE)
if (any(grepl("untranslated message|fuzzy translation", res))) {
cat(sprintf("In %s, found incomplete translations:\n%s\n", po_file, paste(res, collapse="\n")))
stop("Please fix.")
}
linter_env = new.env()
for (f in list.files('.ci/linters/po', full.names=TRUE)) sys.source(f, linter_env)
for (po_file in list.files(pattern = "[.]po$", full.names=TRUE)) {
for (linter in ls(linter_env)) linter_env[[linter]](po_file)
}
cat("All translation quality checks completed successfully!\n")
shell: Rscript {0}
lint-md:
runs-on: ubuntu-latest
Expand Down

0 comments on commit db5312f

Please sign in to comment.