-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpo_extract.R
More file actions
48 lines (43 loc) · 1.4 KB
/
po_extract.R
File metadata and controls
48 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#' Extract messages for translation into a `.pot` file
#'
#' @description
#' `po_extract()` scans your package for strings to be translated and
#' saves them into a `.pot` template file (in the package's `po`
#' directory). You should never modify this file by hand; instead modify the
#' underlying source code and re-run `po_extract()`.
#'
#' If you have existing translations, call [po_update()] after [po_extract()]
#' to update them with the changes.
#'
#' @returns The extracted messages as computed by [get_message_data()],
#' invisibly.
#' @inheritParams get_message_data
#' @export
po_extract <- function(
dir = ".",
custom_translation_functions = list(),
verbose = !is_testing(),
style = NULL) {
message_data <- get_message_data(dir,
custom_translation_functions = custom_translation_functions,
verbose = verbose,
style = style
)
n <- nrow(message_data)
if (!n) {
if (verbose) catf('No messages to translate\n')
return(invisible())
}
if (verbose) catf(ngettext(n, "Found %i message", "Found %i messages"), n, domain=NA)
po_dir <- file.path(dir, 'po')
dir.create(po_dir, showWarnings = FALSE)
desc <- get_desc_data(dir)
po_params = list(
package = desc[['Package']],
version = desc[['Version']],
copyright = NULL,
bugs = NULL
)
write_po_files(message_data, po_dir, po_params, template = TRUE, verbose = verbose)
invisible(message_data)
}