tools (version 3.1.0)

checkPoFiles: Check translation files for inconsistent format strings.

Description

These functions compare formats embedded in English messages with translated strings to check for consistency. checkPoFile checks one file, while checkPoFiles checks all files for a specified language.

Usage

checkPoFile(f, strictPlural = FALSE) checkPoFiles(language, dir = ".")

Arguments

f
a character string giving a single filepath.
strictPlural
whether to compare formats of singular and plural forms in a strict way.
language
a character string giving a language code.
dir
a path to a directory in which to check files.

Value

Both functions return an object of S3 class "check_po_files". A print method is defined for this class to display a report on the differences.

Details

Part of R's internationalization depends on translations of messages in ‘.po’ files. In these files an ‘English’ message taken from the R sources is followed by a translation into another language. Many of these messages are format strings for C or R sprintf and related functions. In these cases, the translation must give a compatible format or an error will be generated when the message is displayed.

The rules for compatibility differ between C and R in several ways. C supports several conversions not supported by R, namely c, u, p, n. It is allowed in C's sprintf() function to have more arguments than are needed by the format string, but in R the counts must match exactly. R requires types of arguments to match, whereas C will do the display whether it makes sense or not.

These functions compromise on the testing as follows. The additional formats allowed in C are accepted, and all differences in argument type or count are reported. As a consequence some reported differences are not errors.

If the strictPlural argument is TRUE, then argument lists must agree exactly between singular and plural forms of messages; if FALSE, then translations only need to match one or the other of the two forms. When checkPoFiles calls checkPoFile, the strictPlural argument is set to TRUE for files with names starting ‘R-’, and to FALSE otherwise.

Items marked as ‘fuzzy’ in the ‘.po’ file are not processed (as they are ignored by the message compiler).

If a difference is found, the translated string is checked for variant percent signs (e.g. the wide percent sign "\uFF05"). Such signs will not be recognized as format specifiers, and are likely to be errors.

References

See the GNU gettext manual for the ‘.po’ file format: http://www.gnu.org/software/gettext/manual/gettext.html.

See Also

xgettext, sprintf

Examples

Run this code
## Not run: 
# checkPoFiles("de", "/path/to/R/src/directory")
# ## End(Not run)

Run the code above in your browser using DataCamp Workspace