gettext package:base R Documentation _T_r_a_n_s_l_a_t_e _T_e_x_t _M_e_s_s_a_g_e_s _D_e_s_c_r_i_p_t_i_o_n: If Native Language Support was enabled in this build of R, attempt to translate character vectors or set where the translations are to be found. _U_s_a_g_e: gettext(..., domain = NULL) ngettext(n, msg1, msg2, domain = NULL) bindtextdomain(domain, dirname = NULL) _A_r_g_u_m_e_n_t_s: ...: One or more character vectors. domain: The 'domain' for the translation. n: a non-negative integer. msg1: the message to be used in English for 'n = 1'. msg2: the message to be used in English for 'n = 0, 2, 3,...'. dirname: The directory in which to find translated message catalogs for the domain. _D_e_t_a_i_l_s: If 'domain' is 'NULL' or '""', a domain is searched for based on the name space which contains the function calling 'gettext' or 'ngettext'. If a suitable domain can be found, each character string is offered for translation, and replaced by its translation into the current language if one is found. Conventionally the domain for R warning/error messages in package 'pkg' is '"R-pkg"', and that for C-level messages is '"pkg"'. For 'gettext', leading and trailing whitespace is ignored when looking for the translation. 'ngettext' is used where the message needs to vary by a single integer. Translating such messages is subject to very specific rules for different languages: see the GNU Gettext Manual. The string will often contain a single instance of '%d' to be used in 'sprintf'. If English is used, 'msg1' is returned if 'n == 1' and 'msg2' in all other cases. _V_a_l_u_e: For 'gettext', a character vector, one element per string in '...'. If translation is not enabled or no domain is found or no translation is found in that domain, the original strings are returned. For 'ngettext', a character string. For 'bindtextdomain', a character string giving the current base directory, or 'NULL' if setting it failed. _S_e_e _A_l_s_o: 'stop' and 'warning' make use of 'gettext' to translate messages. 'xgettext' for extracting translatable strings from R source files. _E_x_a_m_p_l_e_s: bindtextdomain("R") # non-null if and only if NLS is enabled for(n in 0:3) print(sprintf(ngettext(n, "%d variable has missing values", "%d variables have missing values"), n)) ## Not run: ## for translation, those strings should appear in R-pkg.pot as msgid "%d variable has missing values" msgid_plural "%d variables have missing values" msgstr[0] "" msgstr[1] "" ## End(Not run) miss <- c("one", "or", "another") cat(ngettext(length(miss), "variable", "variables"), paste(sQuote(miss), collapse=", "), ngettext(length(miss), "contains", "contain"), "missing values\n") ## better for translators would be to use cat(sprintf(ngettext(length(miss), "variable %s contains missing values\n", "variables %s contain missing values\n"), paste(sQuote(miss), collapse=", ")))