|
1 | 1 | #' Extract user-visible messages from a package |
2 | 2 | #' |
3 | 3 | #' This function looks in the R and src directories of a package for |
4 | | -#' user-visible messages and compiles them as a [data.table::data.table()] |
5 | | -#' to facilitate analyzing this corpus as such. |
| 4 | +#' user-visible messages and compiles them as a |
| 5 | +#' [data.table::data.table()] to facilitate |
| 6 | +#' analyzing this corpus as such. |
6 | 7 | #' |
7 | | -#' @param dir Character, default the present directory; a directory in which |
8 | | -#' an R package is stored. |
| 8 | +#' |
| 9 | +#' @param dir Character, default the present directory; a directory in which an |
| 10 | +#' R package is stored. |
9 | 11 | #' @param custom_translation_functions A `list` with either/both of two |
10 | | -#' components, `R` and `src`, together governing how to extract any |
11 | | -#' non-standard strings from the package. |
| 12 | +#' components, `R` and `src`, together governing how to extract any |
| 13 | +#' non-standard strings from the package. |
12 | 14 | #' |
13 | | -#' See Details in [translate_package()]. |
| 15 | +#' See Details in [`translate_package()`][translate_package]. |
14 | 16 | #' @param style Translation style, either `"base"` or `"explict"`. |
15 | | -#' The default, `NULL`, reads from the `DESCRIPTION` field |
16 | | -#' `Config/potools/style` so you can specify the style once for your |
17 | | -#' package. |
| 17 | +#' The default, `NULL`, reads from the `DESCRIPTION` field |
| 18 | +#' `Config/potools/style` so you can specify the style once for your |
| 19 | +#' package. |
18 | 20 | #' |
19 | | -#' Both styles extract strings explicitly flagged for translation with |
20 | | -#' `gettext()` or `ngettext()`. The base style additionally extracts |
21 | | -#' strings in calls to `stop()`, `warning()`, and `message()`, |
22 | | -#' and to `stopf()`, `warningf()`, and `messagef()` if you have |
23 | | -#' added those helpers to your package. The explicit style also accepts |
24 | | -#' `tr_()` as a short hand for `gettext()`. See |
25 | | -#' `vignette("developer")` for more details. |
| 21 | +#' Both styles extract strings explicitly flagged for translation with |
| 22 | +#' `gettext()` or `ngettext()`. The base style additionally extracts |
| 23 | +#' strings in calls to `stop()`, `warning()`, and `message()`, |
| 24 | +#' and to `stopf()`, `warningf()`, and `messagef()` if you have |
| 25 | +#' added those helpers to your package. The explicit style also accepts |
| 26 | +#' `tr_()` as a short hand for `gettext()`. See |
| 27 | +#' `vignette("developer")` for more details. |
26 | 28 | #' @param verbose Logical, default `TRUE` (except during testing). Should |
27 | | -#' extra information about progress, etc. be reported? |
28 | | -#' @return A `data.table` with the following schema: |
| 29 | +#' extra information about progress, etc. be reported? |
| 30 | +#' @return |
| 31 | +#' A `data.table` with the following schema: |
29 | 32 | #' |
30 | | -#' * `message_source`, `character`, either `"R"` |
31 | | -#' or `"src"`, saying whether the string was found in the R or the src |
32 | | -#' folder of the package |
33 | | -#' * `type`, `character`, either `"singular"` or `"plural"`; |
34 | | -#' `"plural"` means the string came from [ngettext()] and can be pluralized |
35 | | -#' * `file`, `character`, the file where the string was found |
36 | | -#' * `msgid`, `character`, the string (character literal or `char` array as |
| 33 | +#' * `message_source`: `character`, either `"R"` or `"src"`, |
| 34 | +#' saying whether the string was found in the R or the src folder of the |
| 35 | +#' package |
| 36 | +#' * `type`: `character`, either `"singular"` or |
| 37 | +#' `"plural"`; `"plural"` means the string came from |
| 38 | +#' [`ngettext()`][ngettext] and can be pluralized |
| 39 | +#' * `file`: `character`, the file where the string was found |
| 40 | +#' * `msgid`: `character`, the string (character literal or `char` array as |
37 | 41 | #' found in the source); missing for all `type == "plural"` strings |
38 | | -#' * `msgid_plural`, `list(character, character)`, the strings |
| 42 | +#' * `msgid_plural`: `list(character, character)`, the strings |
39 | 43 | #' (character literals or `char` arrays as found in the source); the first |
40 | 44 | #' applies in English for `n=1` (see `ngettext`), while the second |
41 | 45 | #' applies for `n!=1`; missing for all `type == "singular"` strings |
42 | | -#' * `call`, `character`, the full call containing the string |
| 46 | +#' * `call`: `character`, the full call containing the string |
43 | 47 | #' that was found |
44 | | -#' * `line_number`, `integer`, the line in `file` where the string was found |
45 | | -#' * `is_repeat`, `logical`, whether the `msgid` is a duplicate within this |
| 48 | +#' * `line_number`: `integer`, the line in `file` where the string was found |
| 49 | +#' * `is_repeat`: `logical`, whether the `msgid` is a duplicate within this |
46 | 50 | #' `message_source` |
47 | | -#' * `is_marked_for_translation`, `logical`, whether the string is marked for |
48 | | -#' translation (e.g., in R, all character literals supplied to a `...` |
49 | | -#' argument in [stop()] are so marked) |
50 | | -#' * `is_templated`, `logical`,whether the string is templatable (e.g., uses |
51 | | -#' `%s` or other formatting markers) |
| 51 | +#' * `is_marked_for_translation`:`logical`, whether the string is marked for |
| 52 | +#' translation (e.g., in R, all character literals supplied to a `...` argument in |
| 53 | +#' [`stop()`][stop] are so marked) |
| 54 | +#' * `is_templated`, `logical`, whether the string is templatable (e.g., uses |
| 55 | +#' `%s` or other formatting markers) |
52 | 56 | #' @author Michael Chirico |
53 | | -#' @seealso [translate_package()], [write_po_file()] |
| 57 | +#' @seealso [`translate_package()`][translate_package], |
| 58 | +#' [`write_po_file()`][write_po_file] |
54 | 59 | #' @examples |
| 60 | +#' |
55 | 61 | #' pkg <- system.file('pkg', package = 'potools') |
56 | 62 | #' get_message_data(pkg) |
57 | 63 | #' |
|
67 | 73 | #' |
68 | 74 | #' # cleanup |
69 | 75 | #' rm(pkg) |
| 76 | +#' |
| 77 | +#' @export |
70 | 78 | get_message_data = function( |
71 | 79 | dir = ".", |
72 | 80 | custom_translation_functions = list(R = NULL, src = NULL), |
|
0 commit comments