Skip to content

Commit 33c7206

Browse files
Use catf() over messagef() where appropriate
1 parent 86f67b5 commit 33c7206

9 files changed

Lines changed: 35 additions & 27 deletions

R/custom-translators.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
catf = function(fmt, ..., sep=" ", domain="R-potools") {
2+
cat(gettextf(fmt, ..., domain=domain), sep=sep)
3+
}
4+
15
# tends to make some really repetitive messages with call.=TRUE, so always turn it off
26
stopf = function(fmt, ..., domain = NULL) {
37
stop(gettextf(fmt, ..., domain = NULL), domain = NA, call. = FALSE)

R/find_fuzzy_messages.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ find_fuzzy_messages <- function(message_data, lang_file) {
22
old_message_data = get_po_messages(lang_file)
33

44
if (any(idx <- old_message_data$fuzzy == 2L)) {
5-
messagef('Found %d translations marked as deprecated in %s.', sum(idx), lang_file)
6-
message('Typically, this means the corresponding error messages have been refactored.')
7-
message('Reproducing these messages here for your reference since they might still provide some utility.')
5+
messagef(
6+
paste(
7+
'Found %d translations marked as deprecated in %s.',
8+
'Typically, this means the corresponding error messages have been refactored.',
9+
'Reproducing these messages here for your reference since they might still provide some utility.',
10+
sep = '\n'
11+
),
12+
sum(idx), lang_file
13+
)
814

915
dashes = strrep('-', 0.9*getOption('width'))
1016
old_message_data[idx & type == 'singular', {

R/msgmerge.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ run_msgmerge <- function(po_file, pot_file, previous = FALSE, verbose = TRUE) {
1919
# nocov these warnings? i don't know how to trigger them as of this writing.
2020
warningf("Running msgmerge on './po/%s' failed:\n %s", basename(po_file), paste(val, collapse = "\n"))
2121
} else if (verbose) {
22-
messagef(paste(val, collapse = "\n"))
22+
writeLines(val)
2323
}
2424

2525
res <- tools::checkPoFile(po_file, strictPlural = TRUE)
@@ -94,7 +94,7 @@ run_msginit <- function(po_path, pot_path, locale, width = 80L, verbose = TRUE)
9494
if (!identical(attr(val, "status", exact = TRUE), NULL)) {
9595
stopf("Running msginit on '%s' failed", pot_path)
9696
} else if (verbose) {
97-
messagef(paste(val, collapse = "\n"))
97+
writeLines(val)
9898
}
9999
invisible()
100100
}

R/po_compile.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ po_compile = function(dir = ".", package = NULL, lazy = TRUE, verbose = TRUE) {
2424
to_delete <- mo_dirs[!basename(mo_dirs) %in% c(po_metadata$language, "en@quot")]
2525

2626
for (dir in to_delete) {
27-
if (verbose) messagef(
28-
"Found a compiled translation for %s at %s, but no corresponding .po; deleting",
27+
if (verbose) catf(
28+
"Found a compiled translation for %s at %s, but no corresponding .po; deleting\n",
2929
basename(dir), dirname(dir)
3030
)
3131
unlink(dir, recursive = TRUE)
@@ -34,7 +34,7 @@ po_compile = function(dir = ".", package = NULL, lazy = TRUE, verbose = TRUE) {
3434

3535
for (ii in seq_len(nrow(po_metadata))) {
3636
row_ii <- po_metadata[ii]
37-
if (verbose) messagef("Recompiling '%s' %s translation", row_ii$language, row_ii$type)
37+
if (verbose) catf("Recompiling '%s' %s translation\n", row_ii$language, row_ii$type)
3838
run_msgfmt(row_ii$po, row_ii$mo, verbose = verbose)
3939
}
4040

R/po_create.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ po_create <- function(languages, dir = ".", verbose = !is_testing()) {
2222
for (ii in seq_len(nrow(po_files))) {
2323
row_ii <- po_files[ii]
2424
if (file.exists(row_ii$po_path)) {
25-
if (verbose) messagef("Updating '%s' %s translation", row_ii$language, row_ii$type)
25+
if (verbose) catf("Updating '%s' %s translation\n", row_ii$language, row_ii$type)
2626
run_msgmerge(row_ii$po_path, row_ii$pot_path, previous = TRUE, verbose = verbose)
2727
} else {
28-
if (verbose) messagef("Creating '%s' %s translation", row_ii$language, row_ii$type)
28+
if (verbose) catf("Creating '%s' %s translation\n", row_ii$language, row_ii$type)
2929
run_msginit(row_ii$po_path, row_ii$pot_path, locale = row_ii$language, verbose = verbose)
3030
}
3131
}

R/po_extract.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ po_extract <- function(
2727

2828
n <- nrow(message_data)
2929
if (!n) {
30-
if (verbose) message('No messages to translate')
30+
if (verbose) catf('No messages to translate\n')
3131
return(invisible())
3232
}
33-
# TODO: messagef() is double-translating the ngettext() result...
34-
# it needs an escape valve
35-
if (verbose) messagef(ngettext(n, "Found %i message", "Found %i messages"), n)
33+
if (verbose) catf(ngettext(n, "Found %i message", "Found %i messages"), n, domain=NA)
3634

3735
po_dir <- file.path(dir, 'po')
3836
dir.create(po_dir, showWarnings = FALSE)

R/po_update.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ po_update <- function(dir = ".", lazy = TRUE, verbose = !is_testing()) {
3737

3838
for (ii in seq_len(nrow(meta))) {
3939
row_ii <- meta[ii]
40-
if (verbose) messagef("Updating '%s' %s translation", row_ii$language, row_ii$type)
40+
if (verbose) catf("Updating '%s' %s translation\n", row_ii$language, row_ii$type)
4141
run_msgmerge(row_ii$po, row_ii$pot, previous = TRUE, verbose = verbose)
4242
}
4343

R/translate_package.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,13 @@ translate_package = function(
344344
if (tr_update) {
345345
# is it worthwhile to try and distinguish the creation time of the
346346
# R pot file and the src pot file? probably not...
347-
messagef(
348-
"Updating translation template for package '%s' (last updated %s)",
347+
catf(
348+
"Updating translation template for package '%s' (last updated %s)\n",
349349
package,
350350
format(file.info(r_potfile)$atime)
351351
)
352352
} else {
353-
messagef("Starting translations for package '%s'", package)
353+
catf("Starting translations for package '%s'\n", package)
354354
}
355355
}
356356
if (!tr_update) dir.create(po_dir, showWarnings = FALSE)
@@ -411,8 +411,8 @@ translate_package = function(
411411
lang_file <- file.path(po_dir, glue("R-{language}.po"))
412412
if (tr_update && file.exists(lang_file)) {
413413
if (verbose) {
414-
messagef(
415-
'Found existing R translations for %s (%s/%s) in %s. Running msgmerge...',
414+
catf(
415+
'Found existing R translations for %s (%s/%s) in %s. Running msgmerge...\n',
416416
language, metadata$full_name_eng, metadata$full_name_native, lang_file
417417
)
418418
}
@@ -426,8 +426,8 @@ translate_package = function(
426426
lang_file <- file.path(po_dir, glue("{language}.po"))
427427
if (tr_update && file.exists(lang_file)) {
428428
if (verbose) {
429-
messagef(
430-
'Found existing src translations for %s (%s/%s) in %s. Running msgmerge...',
429+
catf(
430+
'Found existing src translations for %s (%s/%s) in %s. Running msgmerge...\n',
431431
language, metadata$full_name_eng, metadata$full_name_native, lang_file
432432
)
433433
}
@@ -448,15 +448,15 @@ translate_package = function(
448448
]
449449

450450
if (!length(new_idx)) {
451-
if (verbose) messagef('Translations for %s are up to date! Skipping.', language)
451+
if (verbose) catf('Translations for %s are up to date! Skipping.\n', language)
452452
next
453453
}
454454
if (verbose) {
455-
messagef(
456-
'Beginning new translations for %s (%s/%s); found %d untranslated messages',
455+
catf(
456+
'Beginning new translations for %s (%s/%s); found %d untranslated messages\n',
457457
language, metadata$full_name_eng, metadata$full_name_native, length(new_idx)
458458
)
459-
message("(To quit translating, press 'Esc'; progress will be saved)")
459+
cat("(To quit translating, press 'Esc'; progress will be saved)\n")
460460
}
461461

462462
po_params$author = prompt('Thanks! Who should be credited with these translations?')

R/write_po_file.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ write_po_files <- function(message_data, po_dir, params, template = FALSE, use_b
3636
))
3737
}
3838

39-
if (verbose) messagef('Writing %s', r_file)
39+
if (verbose) catf('Writing %s\n', r_file)
4040

4141
write_po_file(
4242
message_data[message_source == "R"],

0 commit comments

Comments
 (0)