Skip to content

Commit 4f7f567

Browse files
Fix up procedure for extracting strings to .pot, and add newly-found messages (#6793)
* update .pot again * Update CRAN_Release procedure * Add 'notranslate' in R files, add a mark new strings for translation * More R-side notranslate * Mark many src* strings for non-translation * Caught a few more untranslated messages * sloppy find-and-replace * Un-translate internal error * oops, this is C * nocov hard-to-cover regions * Double-Pl_ for row(s), thread(s) * Make the full message plural for better translator context * Superfluous ')' * rm ws
1 parent f6dca2d commit 4f7f567

24 files changed

+714
-149
lines changed

.dev/CRAN_Release.cmd

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
###############################################
44

55
# 1) Update messages for new release
6-
## (a) Update C template file: src/data.table.pot
7-
## ideally, we are including _() wrapping in
8-
## new PRs throughout dev cycle, and this step
9-
## becomes about tying up loose ends
10-
## Check the output here for translatable messages
11-
xgettext -o /dev/stdout ./*.c \
12-
--keyword=Rprintf --keyword=error --keyword=warning --keyword=STOP --keyword=DTWARN --keyword=Error --keyword=DTPRINT --keyword=snprintf:3
13-
14-
## (b) Update R template file: src/R-data.table.pot
15-
## NB: this relies on R >= 4.0 to remove a bug in update_pkg_po
16-
Rscript -e "tools::update_pkg_po('.')"
6+
dt_custom_translators = list(
7+
R = 'catf:fmt|1',
8+
# TODO(MichaelChirico/potools#318): restore snprintf:3 here too
9+
src = c('STOP:1', 'DTWARN:1', 'DTPRINT:1')
10+
)
11+
message_db =
12+
potools::get_message_data(custom_translation_functions = dt_custom_translators)
13+
potools::check_cracked_messages(message_db)
14+
potools::check_untranslated_cat(message_db)
15+
potools::check_untranslated_src(message_db)
16+
17+
## (b) Update R template files (po/*.pot)
18+
potools::po_extract(custom_translation_functions = dt_custom_translators)
1719

1820
# 2) Open a PR with the new templates & contact the translators
1921
# * zh_CN: @hongyuanjia

R/between.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ inrange = function(x,lower,upper,incbounds=TRUE) {
7575
ops = if (incbounds) c(4L, 2L) else c(5L, 3L) # >=,<= and >,<
7676
verbose = isTRUE(getOption("datatable.verbose"))
7777
if (verbose) {last.started.at=proc.time();catf("forderv(query) took ... ");flush.console()}
78-
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
78+
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()} # notranslate
7979
ans = bmerge(
8080
shallow(subject), query,
8181
icols=1L:2L, xcols=c(1L, 1L),

R/bmerge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
188188
if (verbose) {last.started.at=proc.time();catf(" forder took ... ");flush.console()}
189189
# TODO: could check/reuse secondary indices, but we need 'starts' attribute as well!
190190
xo = forderv(x, xcols, retGrp=TRUE)
191-
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
191+
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()} # notranslate
192192
xg = attr(xo, 'starts', exact=TRUE)
193193
resetcols = head(xcols, non_equi-1L)
194194
if (length(resetcols)) {

R/data.table.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ replace_dot_alias = function(e) {
577577
} else {
578578
irows = as.integer(fsort(as.numeric(irows))) ## nocov; parallelized for numeric, but overhead of type conversion
579579
}
580-
if (verbose) {cat(timetaken(last.started.at), "\n");flush.console()}
580+
if (verbose) {cat(timetaken(last.started.at), "\n");flush.console()} # notranslate
581581
}
582582
## make sure, all columns are taken from x and not from i.
583583
## This is done by simply telling data.table to continue as if there was a simple subset
@@ -634,7 +634,7 @@ replace_dot_alias = function(e) {
634634
irows = irows[irows!=0L]
635635
if (verbose) {last.started.at=proc.time();catf("Inverting irows for notjoin done in ... ");flush.console()}
636636
i = irows = if (length(irows)) seq_len(nrow(x))[-irows] else NULL # NULL meaning all rows i.e. seq_len(nrow(x))
637-
if (verbose) cat(timetaken(last.started.at), "\n")
637+
if (verbose) cat(timetaken(last.started.at), "\n") # notranslate
638638
leftcols = integer() # proceed as if row subset from now on, length(leftcols) is switched on later
639639
rightcols = integer()
640640
# Doing this once here, helps speed later when repeatedly subsetting each column. R's [irows] would do this for each
@@ -892,8 +892,10 @@ replace_dot_alias = function(e) {
892892
}
893893
tt = lengths(byval)
894894
if (any(tt!=xnrow)) {
895-
plural_part <- sprintf(ngettext(length(tt), "The item in the 'by' or 'keyby' list is length %s.", "The items in the 'by' or 'keyby' list have lengths %s."), brackify(tt))
896-
stopf("%s Each must be length %d; the same length as there are rows in x (after subsetting if i is provided).", plural_part, xnrow)
895+
stopf(ngettext(length(tt),
896+
"The item in the 'by' or 'keyby' list is length %s. Each must be length %d; the same length as there are rows in x (after subsetting if i is provided).",
897+
"The items in the 'by' or 'keyby' list have lengths %s. Each must be length %d; the same length as there are rows in x (after subsetting if i is provided)."),
898+
brackify(tt), xnrow, domain=NA)
897899
}
898900
if (is.null(bynames)) bynames = rep.int("",length(byval))
899901
if (length(idx <- which(!nzchar(bynames))) && !bynull) {

R/print.data.table.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
5757
catf("Null data.%s (0 rows and 0 cols)\n", class) # See FAQ 2.5 and NEWS item in v1.8.9
5858
} else {
5959
catf("Empty data.%s (%d rows and %d cols)", class, NROW(x), NCOL(x))
60-
if (length(x)>0L) cat(": ",paste(head(names(x),6L),collapse=","),if(length(x)>6L)"...",sep="")
61-
cat("\n")
60+
if (length(x)>0L) cat(": ",paste(head(names(x),6L),collapse=","),if(length(x)>6L)"...",sep="") # notranslate
61+
cat("\n") # notranslate
6262
}
6363
return(invisible(x))
6464
}

R/test.data.table.R

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
3939
scripts = gsub("[.]bz2$","",scripts)
4040
return(sapply(scripts, function(fn) {
4141
err = try(test.data.table(script=fn, verbose=verbose, pkg=pkg, silent=silent, showProgress=showProgress, testPattern=testPattern))
42-
cat("\n");
42+
cat("\n"); # notranslate
4343
isTRUE(err)
4444
}))
4545
# nocov end
@@ -110,7 +110,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
110110
datatable.old.fread.datetime.character = FALSE
111111
)
112112

113-
cat("getDTthreads(verbose=TRUE):\n") # for tracing on CRAN; output to log before anything is attempted
113+
cat("getDTthreads(verbose=TRUE):\n") # notranslate: for tracing on CRAN; output to log before anything is attempted
114114
getDTthreads(verbose=TRUE) # includes the returned value in the verbose output (rather than dangling '[1] 4'); e.g. "data.table is using 4 threads"
115115
catf("test.data.table() running: %s\n", fn) # print fn to log before attempting anything on it (in case it is missing); on same line for slightly easier grep
116116
assign("testDir", function(x) file.path(fulldir, x), envir=env)
@@ -226,6 +226,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
226226
# does show the full file output these days, so the 13 line limit no longer bites so much. It still bit recently
227227
# when receiving output of R CMD check sent over email, though.
228228
tz = Sys.getenv("TZ", unset=NA)
229+
# notranslate start
229230
cat("\n", date(), # so we can tell exactly when these tests ran on CRAN to double-check the result is up to date
230231
" endian==", .Platform$endian,
231232
", sizeof(long double)==", .Machine$sizeof.longdouble,
@@ -239,6 +240,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
239240
", .libPaths()==", paste0("'", .libPaths(), "'", collapse = ","),
240241
", ", .Call(Cdt_zlib_version),
241242
"\n", sep="")
243+
# notranslate end
242244

243245
if (inherits(err,"try-error")) {
244246
# nocov start
@@ -303,7 +305,7 @@ compactprint = function(DT, topn=2L) {
303305
print(copy(DT)[,(cn):="",verbose=FALSE], topn=topn, class=FALSE)
304306
} else {
305307
print(DT, class=FALSE) # "Empty data.table (0 rows) of <ncol> columns ...
306-
if (ncol(DT)) cat(cn,"\n")
308+
if (ncol(DT)) cat(cn,"\n") # notranslate
307309
}
308310
invisible()
309311
}
@@ -376,14 +378,15 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
376378
if (memtest==1L) gc() # see #5515 for before/after
377379
inum = as.integer(num)
378380
timings[inum, RSS:=max(rss(),RSS), verbose=FALSE] # TODO prefix inum with .. for clarity when that works
379-
if (length(memtest.id) && memtest.id[1L]<=inum && inum<=memtest.id[2L]) cat(rss(),"\n") # after 'testing id ...' output; not using between() as it has verbose output when getOption(datatable.verbose)
381+
if (length(memtest.id) && memtest.id[1L]<=inum && inum<=memtest.id[2L]) cat(rss(),"\n") # notranslate. after 'testing id ...' output; not using between() as it has verbose output when getOption(datatable.verbose)
380382
if (memtest==2L) gc()
381383
}
382384
assign("lasttime", proc.time()[3L], parent.frame(), inherits=TRUE) # after gc() to exclude gc() time from next test when memtest
383385
}, add=TRUE )
384-
if (showProgress)
385-
# \r can't be in gettextf msg
386-
cat("\rRunning test id", numStr, " ") # nocov.
386+
if (showProgress) {
387+
cat("\r") # notranslate: \r can't be in gettextf msg
388+
catf("Running test id", numStr, " ") # nocov.
389+
}
387390
# See PR #4090 for comments about change here in Dec 2019.
388391
# If a segfault error occurs in future and we'd like to know after which test, then arrange for the
389392
# try(sys.source()) in test.data.table() to be run in a separate R process. That process could write out
@@ -534,15 +537,15 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
534537
if (!fail) {
535538
catf("Test %s ran without errors but failed check that x equals y:\n", numStr)
536539
failPrint = function(x, xsub) {
537-
cat(">", substitute(x), "=", xsub, "\n")
540+
cat(">", substitute(x), "=", xsub, "\n") # notranslate
538541
if (is.data.table(x)) compactprint(x) else {
539542
nn = length(x)
540543
catf("First %d of %d (type '%s'): \n", min(nn, 6L), length(x), typeof(x))
541544
# head.matrix doesn't restrict columns
542545
if (length(d <- dim(x))) do.call(`[`, c(list(x, drop = FALSE), lapply(pmin(d, 6L), seq_len)))
543546
else print(head(x))
544547
if (typeof(x) == 'character' && anyNonAscii(x)) {
545-
cat("Non-ASCII string detected, raw representation:\n")
548+
catf("Non-ASCII string detected, raw representation:\n")
546549
print(lapply(head(x), charToRaw))
547550
}
548551
}

0 commit comments

Comments
 (0)