Skip to content

Commit

Permalink
Merge branch 'master' into get-msg-deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Mar 27, 2024
2 parents c093943 + 5e0557f commit d9b0e64
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions R/check_cracked_messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ check_cracked_messages = function(message_data) {
set(dup_messages, ii, "replacement", build_gettextf_call(dup_messages$call_expr[[ii]]))
}

return(dup_messages[ , .(call, file, line_number, replacement)])
dup_messages[ , .(call, file, line_number, replacement)]
}
attr(check_cracked_messages, "diagnostic_tag") =
"R messaging calls that might be better suited for gettextf for ease of translation"
Expand Down Expand Up @@ -105,8 +105,8 @@ count_dots = function(call) {
call,
function(x) {
e = match.call(definition, x)
if (is.null(names(e))) return(length(e) - 1L)
return(length(e) - sum(names(e) %chin% c("call.", "immediate.", "noBreaks.", "domain", "appendLF")) - 1L)
n_excluded = sum(names(e) %chin% c("call.", "immediate.", "noBreaks.", "domain", "appendLF"))
length(e) - n_excluded - 1L
},
integer(1L)
)
Expand Down
6 changes: 3 additions & 3 deletions R/check_untranslated_cat.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ check_untranslated_cat <- function(message_data) {
set(cat_calls, ii, "replacement", build_suggested_cat_call(cat_calls$call_expr[[ii]]))
}

return(cat_calls[
cat_calls[
nzchar(replacement),
.(call, file, line_number, replacement)
])
]
}
attr(check_untranslated_cat, "diagnostic_tag") = "untranslated messaging calls passed through cat()"

Expand Down Expand Up @@ -124,5 +124,5 @@ build_suggested_cat_call = function(e) {
no_translated_subcall <- function(e) {
if (!is.call(e)) return(TRUE)
if (is.name(e[[1L]]) && e[[1L]] %chin% c("gettext", "gettextf", "ngettext")) return(FALSE)
return(all(vapply(e[-1L], no_translated_subcall, logical(1L))))
all(vapply(e[-1L], no_translated_subcall, logical(1L)))
}
4 changes: 2 additions & 2 deletions R/check_untranslated_src.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
check_untranslated_src <- function(message_data) {
if (!is.data.table(message_data)) message_data = as.data.table(message_data)

return(message_data[
message_data[
message_source == "src" & !is_marked_for_translation,
.(call, file, line_number, replacement = NA_character_)
])
]
}
attr(check_untranslated_src, "diagnostic_tag") <- "src messaging calls that were not properly marked for translation"
2 changes: 1 addition & 1 deletion R/explain_plurals.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ po_explain_plurals <- function(language, index) {
)
]
}
return(invisible())
invisible()
}

# just here to generate translations. comes from the PLURAL_RANGE_STRINGS csv
Expand Down
52 changes: 26 additions & 26 deletions R/get_r_messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ parse_r_files = function(dir, is_base) {
return(out)
}
names(out) = r_files
return(out)
out
}

# inspired by the --keyword argument in gettext, but customized to make sense for R.
Expand Down Expand Up @@ -463,32 +463,32 @@ drop_suppressed_and_named = function(calls_data, expr_data, target_args) {
build_call = function(lines, comments, params) {
if (params$line1 == params$line2) {
return(substr(adjust_tabs(lines[params$line1]), params$col1, params$col2))
} else {
lines = lines[params$line1:params$line2]

# substring not substr here so we can eschew providing
# last=nchar(lines[1L]) because we'd need to recalculate it after adjust_tabs()
lines[1L] = substring(adjust_tabs(lines[1L]), params$col1)
lines[length(lines)] = substring(adjust_tabs(lines[length(lines)]), 1L, params$col2)

# strip comments, _after_ getting the tab-adjusted column #s
for (ii in seq_len(nrow(comments))) {
# we've already subset lines, so line numbers have to be re-mapped
adj_line_idx = comments$line1[ii] - params$line1 + 1L
# column number has to be re-mapped relative to col1 as well, but only on line1 itself
col_adj = if (adj_line_idx == 1L) params$col1 else 1L
lines[adj_line_idx] = substr(
lines[adj_line_idx],
1L,
comments$col1[ii] - col_adj
)
}
}

# strip internal whitespace across lines in the call
# NB: eventually, this will need to be smarter about multi-line STR_CONST...
# for now, just wave hands around those....
return(paste(trimws(lines), collapse = " "))
lines = lines[params$line1:params$line2]

# substring not substr here so we can eschew providing
# last=nchar(lines[1L]) because we'd need to recalculate it after adjust_tabs()
lines[1L] = substring(adjust_tabs(lines[1L]), params$col1)
lines[length(lines)] = substring(adjust_tabs(lines[length(lines)]), 1L, params$col2)

# strip comments, _after_ getting the tab-adjusted column #s
for (ii in seq_len(nrow(comments))) {
# we've already subset lines, so line numbers have to be re-mapped
adj_line_idx = comments$line1[ii] - params$line1 + 1L
# column number has to be re-mapped relative to col1 as well, but only on line1 itself
col_adj = if (adj_line_idx == 1L) params$col1 else 1L
lines[adj_line_idx] = substr(
lines[adj_line_idx],
1L,
comments$col1[ii] - col_adj
)
}

# strip internal whitespace across lines in the call
# NB: eventually, this will need to be smarter about multi-line STR_CONST...
# for now, just wave hands around those....
paste(trimws(lines), collapse = " ")
}

adjust_tabs = function(l) {
Expand Down Expand Up @@ -526,7 +526,7 @@ clean_text = function(x) {
# e.g. in 'a string with an \"escaped\" quote', the escapes for " disappear after parsing. See #128
x = gsub("(?:^|(?<![\\\\]))[\\\\](['\"])", "\\1", x, perl = TRUE)
x = gsub('\\\\', '\\', x, fixed = TRUE)
return(x)
x
}

string_schema = function() {
Expand Down
6 changes: 3 additions & 3 deletions R/get_src_messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ preprocess = function(contents) {
)
ii = ii + 1L
}
return(contents)
contents
}

is_outside_char_array = function(char_pos, arrays) {
Expand Down Expand Up @@ -410,7 +410,7 @@ match_parens = function(file, contents, arrays) {
all_parens[idx & lparen, "paren_end" := fcase(!next_paren, next_start)]
all_parens[ , c("next_paren", "next_start") := NULL]
}
return(all_parens[(lparen)])
all_parens[(lparen)]
}

build_msgid = function(left, right, starts, ends, contents) {
Expand Down Expand Up @@ -474,7 +474,7 @@ build_msgid_plural = function(fun, left, right, starts, ends, contents, message_
msgid = paste(safe_substring(contents, starts[ii:jj - 1L] + 1L, ends[ii:jj - 1L] - 1L), collapse = '')
msgid_plural = msgid
}
return(list(msgid_plural))
list(msgid_plural)
}

get_grout = function(left, right, starts, ends, contents) {
Expand Down
4 changes: 2 additions & 2 deletions R/msgmerge.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ run_msgfmt = function(po_file, mo_file, verbose) {
immediate. = TRUE
)
}
return(invisible())
invisible()
}

update_en_quot_mo_files <- function(dir, verbose) {
Expand All @@ -73,7 +73,7 @@ update_en_quot_mo_files <- function(dir, verbose) {
)
unlink(po_file)
}
return(invisible())
invisible()
}

# https://www.gnu.org/software/gettext/manual/html_node/msginit-Invocation.html
Expand Down
8 changes: 4 additions & 4 deletions R/read_translation.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ set_prompt_conn <- function() {
conn <- file(conn, "r")
}
assign("prompt_conn", conn, envir=.potools)
return(invisible())
invisible()
}

unset_prompt_conn <- function() {
if (!exists("prompt_conn", envir=.potools) || inherits(.potools$prompt_conn, "terminal")) return(invisible())
close(.potools$prompt_conn)
return(invisible())
if (exists("prompt_conn", envir=.potools) && !inherits(.potools$prompt_conn, "terminal"))
close(.potools$prompt_conn)
invisible()
}

# would be great to use readline() but it has several fatal flaws:
Expand Down
2 changes: 1 addition & 1 deletion R/specials_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ all.equal.specials_metadata = function(target, current, ...) {
# found in x, not y (i.e., in msgid, not msgstr)

# else target/current have the same number of rows
return(TRUE)
TRUE
}
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ get_directory = function(dir) {
if (!file.info(dir)$isdir) {
stopf('%s is not a directory', dir)
}
return(normalizePath(dir))
normalizePath(dir)
}

# check dir is a package & return its name & version
Expand Down Expand Up @@ -95,7 +95,7 @@ list_package_files = function(dir, subdir, subsubdirs = character(), pattern = N
`%is_base_call%` = function(e, f) {
if (e %is_name% f) return(TRUE)
if (!is.call(e) || length(e) != 3L) return(FALSE)
return(e[[1L]] %is_name% "::" && e[[2L]] %is_name% "base" && e[[3L]] %is_name% f)
e[[1L]] %is_name% "::" && e[[2L]] %is_name% "base" && e[[3L]] %is_name% f
}

gettextify = function(e, sep = '') {
Expand Down

0 comments on commit d9b0e64

Please sign in to comment.