Skip to content

Commit 635f953

Browse files
Reorganize .po linters for extensibility, similarity to other checks
1 parent 8476fdd commit 635f953

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
incomplete_translation_linter <- function(po_file) {
2+
res = system2("msgfmt", c("--statistics", po_file, "-o", tempfile()), stdout=TRUE, stderr=TRUE)
3+
if (any(grepl("untranslated message|fuzzy translation", res))) {
4+
cat(sprintf("In %s, found incomplete translations:\n%s\n", po_file, paste(res, collapse="\n")))
5+
stop("Please fix.")
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tools_check_linter = function(po_file) {
2+
res = tools::checkPoFile(po_file, strictPlural=TRUE)
3+
if (NROW(res)) {
4+
print(res)
5+
stop("Fix the above .po file issues.")
6+
}
7+
}

.ci/linters/po/utf8_linter.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
utf8_linter <- function(po_file) {
2+
if (!any(grepl("charset=UTF-8", readLines(po_file), fixed=TRUE)))
3+
stop("In ", po_file, ", please use charset=UTF-8.")
4+
}

.github/workflows/code-quality.yaml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,11 @@ jobs:
5656
- uses: r-lib/actions/setup-r@v2
5757
- name: Check translations
5858
run: |
59-
setwd("po")
60-
for (po_file in list.files(pattern = "[.]po$")) {
61-
res = tools::checkPoFile(po_file, strictPlural=TRUE)
62-
if (NROW(res)) { print(res); stop("Fix the above .po file issues.") }
63-
64-
if (!any(grepl("charset=UTF-8", readLines(po_file), fixed=TRUE)))
65-
stop("In ", po_file, ", please use charset=UTF-8.")
66-
67-
res = system2("msgfmt", c("--statistics", po_file, "-o", tempfile()), stdout=TRUE, stderr=TRUE)
68-
if (any(grepl("untranslated message|fuzzy translation", res))) {
69-
cat(sprintf("In %s, found incomplete translations:\n%s\n", po_file, paste(res, collapse="\n")))
70-
stop("Please fix.")
71-
}
59+
linter_env = new.env()
60+
for (f in list.files('.ci/linters/po', full.names=TRUE)) sys.source(f, linter_env)
61+
for (po_file in list.files(pattern = "[.]po$", full.names=TRUE)) {
62+
for (linter in ls(linter_env)) linter_env[[linter]](po_file)
7263
}
73-
cat("All translation quality checks completed successfully!\n")
7464
shell: Rscript {0}
7565
lint-md:
7666
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)