Dictionaries allow psychTestR tests to support multiple languages during test administration. These dictionaries (class name: i18n_dict) define mappings between string keys (e.g. prompt1) and (potentially) multiple outputs, each corresponding to different languages (e.g. English, German). The dictionary is passed as an argument to new_timeline, and provides the context for the evaluation of calls to i18n, responsible for translating individual terms.

Methods

i18n_dict$new(x, markdown) defines and returns a new dictionary which can be saved as an object. Its first argument, x, should be a data frame defining the dictionary. Each row of this data frame should correspond to a term to be translated. It should have a column entitled 'key', which defines the identifying keys for each term. All other columns should provide translations into different languages, with the language being identified by the column name, according to ISO 639-2 conventions (lower-case, e.g. 'en'). The second argument, markdown, is a scalar Boolean (default = TRUE) that determines whether the data frame is formatted in Markdown or not (Markdown allows for efficient and readable text markup, e.g. italic and bold). Text is parsed according to standard Markdown conventions, with one addition: two successive backslashes (written "\" in a text file, or "\\" in R) are interpreted as a new paragraph.

x$as.data.frame, where x is a dictionary object, converts the dictionary back to a data frame representation.

x$edit(key, language, new), edits a given entry in the dictionary for a given key and language, replacing it with the value new. See the vignette "Editing dictionaries" for details.

x$translate(key, language, allow_missing) uses the dictionary x to translate key into language. If allow_missing is TRUE, then NULL is returned when no translation is found, otherwise an error is thrown.

Methods


Method new()

Usage

i18n_dict$new(x, markdown = TRUE)


Method as.data.frame()

Usage

i18n_dict$as.data.frame()


Method translate()

Usage

i18n_dict$translate(key, language, allow_missing = FALSE)


Method edit()

Usage

i18n_dict$edit(key, language, new)


Method print()

Usage

i18n_dict$print(...)


Method clone()

The objects of this class are cloneable with this method.

Usage

i18n_dict$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.