Translates a single key or vector of keys to the currently active locale. This is the primary function for internationalization in pharmhand.
Arguments
- key
Character. A translation key or vector of keys (e.g.,
"treatment","hazard_ratio",c("age", "sex")).- locale
Character or NULL. Optional locale to use instead of the current default. If NULL (default), uses the locale from
set_locale().
Value
Character vector of translated strings. If a key is not found, returns the key itself with a warning.
Details
Translation keys are case-insensitive and use underscores to separate
words (snake_case). Available keys can be viewed using get_translations().
Custom translations can be added using add_translation(). Custom
translations take precedence over built-in translations.
Examples
# English (default)
tr("treatment")
#> [1] "Behandlung"
# [1] "Treatment"
# German
tr("treatment", locale = "de")
#> [1] "Behandlung"
# [1] "Behandlung"
# Multiple keys
tr(c("age", "sex", "race"))
#> [1] "Alter" "Geschlecht" "Ethnie"
# [1] "Age" "Sex" "Race"
# Using current locale
set_locale("de")
tr("hazard_ratio")
#> [1] "Hazard Ratio"
# [1] "Hazard Ratio"
