Skip to content

Commit 9029d79

Browse files
Unify messages for translation (#7562)
* Unify messages in R * Unify messages in C * match tests to new messages * last re-fix
1 parent 47c1d3e commit 9029d79

29 files changed

Lines changed: 114 additions & 111 deletions

R/as.data.table.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ as.data.table.array = function(x, keep.rownames=FALSE, key=NULL, sorted=TRUE, va
8989
stopf("as.data.table.array method should only be called for arrays with 3+ dimensions; use the matrix method for 2-dimensional arrays")
9090
if (!is.character(value.name) || length(value.name)!=1L || is.na(value.name) || !nzchar(value.name))
9191
stopf("Argument 'value.name' must be scalar character, non-NA and at least one character")
92-
if (!is.logical(sorted) || length(sorted)!=1L || is.na(sorted))
93-
stopf("Argument 'sorted' must be scalar logical and non-NA")
94-
if (!is.logical(na.rm) || length(na.rm)!=1L || is.na(na.rm))
95-
stopf("Argument 'na.rm' must be scalar logical and non-NA")
92+
if (!isTRUEorFALSE(sorted))
93+
stopf("'%s' must be TRUE or FALSE", "sorted")
94+
if (!isTRUEorFALSE(na.rm))
95+
stopf("'%s' must be TRUE or FALSE", "na.rm")
9696
if (!missing(sorted) && !is.null(key))
9797
stopf("Please provide either 'key' or 'sorted', but not both.")
9898

R/data.table.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,8 @@ replace_dot_alias = function(e) {
15091509
###########################################################################
15101510

15111511
o__ = integer()
1512-
if (".N" %chin% ansvars) stopf("The column '.N' can't be grouped because it conflicts with the special .N variable. Try setnames(DT,'.N','N') first.")
1513-
if (".I" %chin% ansvars) stopf("The column '.I' can't be grouped because it conflicts with the special .I variable. Try setnames(DT,'.I','I') first.")
1512+
if (".N" %chin% ansvars) stopf("The column '.%1$s' can't be grouped because it conflicts with the special .%1$s variable. Try setnames(DT,'.%1$s','%1$s') first.", "N")
1513+
if (".I" %chin% ansvars) stopf("The column '.%1$s' can't be grouped because it conflicts with the special .%1$s variable. Try setnames(DT,'.%1$s','%1$s') first.", "I")
15141514
SDenv$.iSD = NULL # null.data.table()
15151515
SDenv$.xSD = NULL # null.data.table() - introducing for FR #2693 and Gabor's post on fixing for FAQ 2.8
15161516

@@ -2530,7 +2530,7 @@ Ops.data.table = function(e1, e2 = NULL)
25302530
}
25312531

25322532
split.data.table = function(x, f, drop = FALSE, by, sorted = FALSE, keep.by = TRUE, flatten = TRUE, ..., verbose = getOption("datatable.verbose")) {
2533-
if (!is.data.table(x)) internal_error("x argument to split.data.table must be a data.table") # nocov
2533+
if (!is.data.table(x)) internal_error("'%s' argument to split.data.table must be a data.table") # nocov
25342534
stopifnot(is.logical(drop), is.logical(sorted), is.logical(keep.by), is.logical(flatten))
25352535
# split data.frame way, using `f` and not `by` argument
25362536
if (!missing(f)) {
@@ -3110,10 +3110,10 @@ rowid = function(..., prefix=NULL) {
31103110

31113111
rowidv = function(x, cols=seq_along(x), prefix=NULL) {
31123112
if (!is.null(prefix) && (!is.character(prefix) || length(prefix) != 1L))
3113-
stopf("'prefix' must be NULL or a character vector of length 1.")
3113+
stopf("'prefix' must be NULL or a character vector of length 1")
31143114
if (is.atomic(x)) {
31153115
if (!missing(cols) && !is.null(cols))
3116-
stopf("x is a single vector, non-NULL 'cols' doesn't make sense.")
3116+
stopf("x is a single vector, non-NULL 'cols' doesn't make sense")
31173117
cols = 1L
31183118
x = as_list(x)
31193119
} else if (!length(cols)) {
@@ -3135,10 +3135,10 @@ rleid = function(..., prefix=NULL) {
31353135

31363136
rleidv = function(x, cols=seq_along(x), prefix=NULL) {
31373137
if (!is.null(prefix) && (!is.character(prefix) || length(prefix) != 1L))
3138-
stopf("'prefix' must be NULL or a character vector of length 1.")
3138+
stopf("'prefix' must be NULL or a character vector of length 1")
31393139
if (is.atomic(x)) {
31403140
if (!missing(cols) && !is.null(cols))
3141-
stopf("x is a single vector, non-NULL 'cols' doesn't make sense.")
3141+
stopf("x is a single vector, non-NULL 'cols' doesn't make sense")
31423142
cols = 1L
31433143
x = as_list(x)
31443144
} else if (!length(cols)) {

R/duplicated.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ duplicated.data.table = function(x, incomparables=FALSE, fromLast=FALSE, by=seq_
44
.NotYetUsed("incomparables != FALSE")
55
}
66
if (nrow(x) == 0L || ncol(x) == 0L) return(logical(0L)) # fix for bug #28
7-
if (is.na(fromLast) || !is.logical(fromLast)) stopf("'fromLast' must be TRUE or FALSE")
7+
if (is.na(fromLast) || !is.logical(fromLast)) stopf("'%s' must be TRUE or FALSE", "fromLast")
88
if (!length(by)) by = NULL #4594
99
query = .duplicated.helper(x, by)
1010

R/fcast.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ aggregate_funs = function(funs, vals, sep="_", ...) {
122122
}
123123

124124
dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ..., margins = NULL, subset = NULL, fill = NULL, drop = TRUE, value.var = guess(data), verbose = getOption("datatable.verbose"), value.var.in.dots = FALSE, value.var.in.LHSdots = value.var.in.dots, value.var.in.RHSdots = value.var.in.dots) {
125-
if (!is.data.table(data)) stopf("'data' must be a data.table.")
125+
if (!is.data.table(data)) stopf("'%s' must be a data.table", "data")
126126
drop = as.logical(rep_len(drop, 2L))
127-
if (anyNA(drop)) stopf("'drop' must be logical TRUE/FALSE")
127+
if (anyNA(drop)) stopf("'drop' must be logical vector with no missing entries")
128128
if (!isTRUEorFALSE(value.var.in.dots))
129-
stopf("Argument 'value.var.in.dots' should be logical TRUE/FALSE")
130-
if (!isTRUEorFALSE(value.var.in.LHSdots) || !isTRUEorFALSE(value.var.in.RHSdots))
131-
stopf("Arguments 'value.var.in.LHSdots', 'value.var.in.RHSdots' should be logical TRUE/FALSE")
129+
stopf("'%s' must be TRUE or FALSE", "value.var.in.dots")
130+
if (!isTRUEorFALSE(value.var.in.LHSdots))
131+
stopf("'%s' must be TRUE or FALSE", "value.var.in.LHSdots")
132+
if (!isTRUEorFALSE(value.var.in.RHSdots))
133+
stopf("'%s' must be TRUE or FALSE", "value.var.in.RHSdots")
132134
# #2980 if explicitly providing fun.aggregate=length but not a value.var,
133135
# just use the last column (as guess(data) would do) because length will be
134136
# the same on all columns

R/fmelt.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ measurev = function(fun.list, sep="_", pattern, cols, multiple.keyword="value.na
181181
melt.data.table = function(data, id.vars, measure.vars, variable.name = "variable",
182182
value.name = "value", ..., na.rm = FALSE, variable.factor = TRUE, value.factor = FALSE,
183183
verbose = getOption("datatable.verbose")) {
184-
if (!is.data.table(data)) stopf("'data' must be a data.table")
184+
if (!is.data.table(data)) stopf("'%s' must be a data.table", "data")
185185
for(type.vars in c("id.vars","measure.vars")){
186186
sub.lang <- substitute({
187187
if (missing(VAR)) VAR=NULL

R/foverlaps.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ foverlaps = function(x, y, by.x=key(x) %||% key(y), by.y=key(y), maxgap=0L, mino
99
stopf("maxgap must be a non-negative integer value of length 1")
1010
if (!length(minoverlap) || length(minoverlap) != 1L || is.na(minoverlap) || minoverlap < 1L)
1111
stopf("minoverlap must be a positive integer value of length 1")
12-
if (!length(which) || length(which) != 1L || is.na(which))
13-
stopf("which must be a logical vector of length 1. Either TRUE/FALSE")
12+
if (!isTRUEorFALSE(which))
13+
stopf("'%s' must be TRUE or FALSE", "which")
1414
if (!length(nomatch) || length(nomatch) != 1L || (!is.na(nomatch) && nomatch!=0L))
1515
stopf("nomatch must either be NA or NULL")
1616
type = match.arg(type)
@@ -33,9 +33,9 @@ foverlaps = function(x, y, by.x=key(x) %||% key(y), by.y=key(y), maxgap=0L, mino
3333
by.y = names(y)[by.y]
3434
}
3535
if (!is.character(by.x))
36-
stopf("A non-empty vector of column names or numbers is required for by.x")
36+
stopf("A non-empty vector of column names or numbers is required for '%s'", "by.x")
3737
if (!is.character(by.y))
38-
stopf("A non-empty vector of column names or numbers is required for by.y")
38+
stopf("A non-empty vector of column names or numbers is required for '%s'", "by.y")
3939
if (!identical(by.y, key(y)[seq_along(by.y)]))
4040
stopf("The first %d columns of y's key must be identical to the columns specified in by.y.", length(by.y))
4141
if (anyNA(chmatch(by.x, names(x))))

R/frank.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ frankv = function(x, cols=seq_along(x), order=1L, na.last=TRUE, ties.method=c("a
2020
} else {
2121
cols = colnamesInt(x, cols, check_dups=TRUE)
2222
if (!length(cols))
23-
stopf("x is a list, 'cols' can not be 0-length")
23+
stopf("x is a list, 'cols' cannot be 0-length.")
2424
}
2525
# need to unlock for #4429
2626
x = .shallow(x, cols, unlock = TRUE) # shallow copy even if list..

R/frollapply.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ frollapply = function(X, N, FUN, ..., by.column=TRUE, fill=NA, align=c("right","
133133
stopf("'n' is deprecated in frollapply, use 'N' instead")
134134
}
135135
if (!isTRUEorFALSE(by.column))
136-
stopf("'by.column' must be TRUE or FALSE")
136+
stopf("'%s' must be TRUE or FALSE", "by.column")
137137
if (!isTRUEorFALSE(adaptive))
138-
stopf("'adaptive' must be TRUE or FALSE")
138+
stopf("'%s' must be TRUE or FALSE", "adaptive")
139139
if (!isTRUEorFALSE(partial))
140-
stopf("'partial' must be TRUE or FALSE")
140+
stopf("'%s' must be TRUE or FALSE", "partial")
141141
if (!isTRUEorFALSE(give.names))
142-
stopf("'give.names' must be TRUE or FALSE")
142+
stopf("'%s' must be TRUE or FALSE", "give.names")
143143
if (!isTRUEorFALSE(simplify) && !is.function(simplify))
144-
stopf("'simplify' must be TRUE or FALSE or a function")
144+
stopf("'%s' must be TRUE or FALSE or a function", "simplify")
145145

146146
align = match.arg(align)
147147
FUN = match.fun(FUN)

R/groupingsets.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ rollup = function(x, ...) {
44
rollup.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) {
55
# input data type basic validation
66
if (!is.data.table(x))
7-
stopf("Argument 'x' must be a data.table object", class="dt_invalid_input_error")
7+
stopf("'%s' must be a data.table", "x", class="dt_invalid_input_error")
88
if (!is.character(by))
99
stopf("Argument 'by' must be a character vector of column names used in grouping.")
1010
if (!is.logical(id))
@@ -22,7 +22,7 @@ cube = function(x, ...) {
2222
cube.data.table = function(x, j, by, .SDcols, id = FALSE, label = NULL, ...) {
2323
# input data type basic validation
2424
if (!is.data.table(x))
25-
stopf("Argument 'x' must be a data.table object", class="dt_invalid_input_error")
25+
stopf("'%s' must be a data.table", "x", class="dt_invalid_input_error")
2626
if (!is.character(by))
2727
stopf("Argument 'by' must be a character vector of column names used in grouping.")
2828
if (!is.logical(id))
@@ -44,7 +44,7 @@ groupingsets = function(x, ...) {
4444
groupingsets.data.table = function(x, j, by, sets, .SDcols, id = FALSE, jj, label = NULL, enclos = parent.frame(), ...) {
4545
# input data type basic validation
4646
if (!is.data.table(x))
47-
stopf("Argument 'x' must be a data.table object")
47+
stopf("'%s' must be a data.table", "x")
4848
if (ncol(x) < 1L)
4949
stopf("Argument 'x' is a 0-column data.table; no measure to apply grouping over.")
5050
if (anyDuplicated(names(x)) > 0L)

R/helpers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# convert char to factor retaining order #4837
44
fctr = function(x, levels=unique(x), ..., sort=FALSE, rev=FALSE) {
55
if (!isTRUEorFALSE(sort))
6-
stopf("argument 'sort' must be TRUE or FALSE")
6+
stopf("'%s' must be TRUE or FALSE", "sort")
77
if (!isTRUEorFALSE(rev))
8-
stopf("argument 'rev' must be TRUE or FALSE")
8+
stopf("'%s' must be TRUE or FALSE", "rev")
99
if (sort) levels = sort(levels)
1010
if (rev) levels = frev(levels)
1111
factor(x, levels=levels, ...)

0 commit comments

Comments
 (0)