Title: | Simple Translation Between Different Languages |
---|---|
Description: | Message translation is often managed with 'po' files and the 'gettext' programme, but sometimes another solution is needed. In contrast to 'po' files, a more flexible approach is used as in the Fluent <https://projectfluent.org/> project with R Markdown snippets. The key-value approach allows easier handling of the translated messages. |
Authors: | Sigbert Klinke [aut, cre] |
Maintainer: | Sigbert Klinke <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2024-11-23 03:47:23 UTC |
Source: | https://github.com/sigbertklinke/stranslate |
Returns the names of all functions currently available.
allFunctions()
allFunctions()
character vector of functions names
https://stackoverflow.com/questions/4267744/is-there-a-way-to-get-a-vector-with-the-name-of-all-functions-that-one-could-use
allFunctions()
allFunctions()
Extract all texts, getMsg
, or setMsg
calls in the R files given.
Note that the '
and "
are part of the string, thus 'ROUND'
has a length of 7!
findText(files, pattern = "\\w+{2,}")
findText(files, pattern = "\\w+{2,}")
files |
character: names of R files to analyse |
pattern |
character: pattern to match a string (default: |
a data frame with the columns
file
with file name
line
the line number
type
if a string constant (STR_CONST
), a getMsg
(GETMSG
), or a setMsg
(SETMSG
) was found
text
the text of the string constant or the key used in getMsg
or setMsg
findText(system.file("messages", "messages.R", package="stranslate"))
findText(system.file("messages", "messages.R", package="stranslate"))
Returns a message. The first parameter must be the key to the message. For details read the vignette vignette("stranslate")
.
getMsg( ..., .domain = getOption("stranslate.domain"), .lang = getOption("stranslate.lang") )
getMsg( ..., .domain = getOption("stranslate.domain"), .lang = getOption("stranslate.lang") )
... |
parameter(s) given to the function |
.domain |
character: domain name (default: |
.lang |
character: language to use (default: |
the (translated) message
# without a parameter getMsg("DOMAIN_UNIQUE", .domain="stranslate", .lang="en") getMsg('DOMAIN_UNIQUE', .domain="stranslate", .lang="de") getMsg(DOMAIN_UNIQUE, .domain="stranslate") # with a parameter getMsg(LANGUAGE="english", .domain="stranslate", .lang="en") getMsg(LANGUAGE="deutsch", .domain="stranslate", .lang="de") # which system language is used? getMsg(LANGUAGE=Sys.getenv("LANG"), .domain="stranslate")
# without a parameter getMsg("DOMAIN_UNIQUE", .domain="stranslate", .lang="en") getMsg('DOMAIN_UNIQUE', .domain="stranslate", .lang="de") getMsg(DOMAIN_UNIQUE, .domain="stranslate") # with a parameter getMsg(LANGUAGE="english", .domain="stranslate", .lang="en") getMsg(LANGUAGE="deutsch", .domain="stranslate", .lang="de") # which system language is used? getMsg(LANGUAGE=Sys.getenv("LANG"), .domain="stranslate")
Checks if a txt
consists of valid name(s):
A name must start with a letter and can be a combination of letters, digits, period(.) and underscore(_).
Reserved words cannot be used as a name (TRUE, FALSE, NULL, if...)
isName(txt)
isName(txt)
txt |
character: name(s) to check |
a logical vector
isName("?plot") isName(".default")
isName("?plot") isName(".default")
Returns which loaded language will be used for finding a message depending on .domain
.
language( lang = getOption("stranslate.lang"), available.languages = NULL, .domain = NULL )
language( lang = getOption("stranslate.lang"), available.languages = NULL, .domain = NULL )
lang |
character: a language code, e.g. from ISO-639 |
available.languages |
character: names of languages (default: |
.domain |
character: domain names (default: |
character of languages use to find a message
print(options("stranslate.lang")) # current default language language("de_AT", c("de", "de_IT")) # request austrian german # loadMsg(system.file("messages", "messages.txt", package = "stranslate")) language("de_AT") # request austrian german language("tlh") # request klingon, not available -> "en"
print(options("stranslate.lang")) # current default language language("de_AT", c("de", "de_IT")) # request austrian german # loadMsg(system.file("messages", "messages.txt", package = "stranslate")) language("de_AT") # request austrian german language("tlh") # request klingon, not available -> "en"
Lists all keys in all languages in a specific domain or all domains (default).
listMsg(.domain = NULL)
listMsg(.domain = NULL)
.domain |
character: domains(s) to list (default: |
nothing
listMsg("stranslate") listMsg() # load some more text loadMsg(system.file("messages/messages.txt", package="stranslate"), .overwrite=TRUE) # avoid warning listMsg()
listMsg("stranslate") listMsg() # load some more text loadMsg(system.file("messages/messages.txt", package="stranslate"), .overwrite=TRUE) # avoid warning listMsg()
Loads translated messages from one (or more) file into package environment. For details read the vignette vignette("stranslate")
.
loadMsg( files, .domain = getOption("stranslate.domain"), .lang = "en", .silent = TRUE, .overwrite = FALSE )
loadMsg( files, .domain = getOption("stranslate.domain"), .lang = "en", .silent = TRUE, .overwrite = FALSE )
files |
character: names of text file(s) with translated messages |
.domain |
character: domain namesd (default: |
.lang |
character: default language (default: 'en') |
.silent |
logical: should outputs be displayed during the loading process and then |
.overwrite |
logical: should keys be overwritten (default: |
invisibly the current message environment
# note "messages/messages.txt" contains only english and german ;) loadMsg(system.file("messages/messages.txt", package="stranslate"), .overwrite=TRUE) # avoid warning # english getMsg(ROUND=0, .lang="en") getMsg(ROUND=1, .lang="en") getMsg(ROUND=2, .lang="en") # english getMsg(ROUND=0, .lang="de") getMsg(ROUND=1, .lang="de") getMsg(ROUND=2, .lang="de") # default language or if not available then english getMsg(ROUND=0) getMsg(ROUND=1) getMsg(ROUND=2)
# note "messages/messages.txt" contains only english and german ;) loadMsg(system.file("messages/messages.txt", package="stranslate"), .overwrite=TRUE) # avoid warning # english getMsg(ROUND=0, .lang="en") getMsg(ROUND=1, .lang="en") getMsg(ROUND=2, .lang="en") # english getMsg(ROUND=0, .lang="de") getMsg(ROUND=1, .lang="de") getMsg(ROUND=2, .lang="de") # default language or if not available then english getMsg(ROUND=0) getMsg(ROUND=1) getMsg(ROUND=2)
Sets the language and the domain.
setLang(.lang = "en", .domain = getOption("stranslate.domain"))
setLang(.lang = "en", .domain = getOption("stranslate.domain"))
.lang |
character: language (default: |
.domain |
character: domain (default: |
invisibly the language set
setLang('tlh') # use klingon now ;)
setLang('tlh') # use klingon now ;)
Sets for a key the default message and other optional messages. The first argument specifies the key and the default message. Further named arguments give the message if the key is the same as the name,
setMsg(..., .silent = TRUE, .overwrite = FALSE)
setMsg(..., .silent = TRUE, .overwrite = FALSE)
... |
first argument is a key and the default message, further named arguments give optional messages |
.silent |
logical: should the key shown during the process |
.overwrite |
logical: should keys be overwritten (default: |
returns invisibly the key
setLang("de", .domain="round") # If ROUND=0 then getMsg returns 'Runden Sie ihr Ergebnis auf eine ganze Zahl' # If ROUND=1 then getMsg returns 'Runden Sie ihr Ergebnis auf eine Nachkommastelle' # Otherwise getMsg retuns 'Runden Sie ihr Ergebnis auf `r ROUND` Nachkommastellen' setMsg(ROUND='Runden Sie ihr Ergebnis auf `r ROUND` Nachkommastellen', '0'='Runden Sie ihr Ergebnis auf eine ganze Zahl', '1'='Runden Sie ihr Ergebnis auf eine Nachkommastelle') getMsg(ROUND=0, .lang="de", .domain="round") getMsg(ROUND=1, .lang="de", .domain="round") getMsg(ROUND=2, .lang="de", .domain="round")
setLang("de", .domain="round") # If ROUND=0 then getMsg returns 'Runden Sie ihr Ergebnis auf eine ganze Zahl' # If ROUND=1 then getMsg returns 'Runden Sie ihr Ergebnis auf eine Nachkommastelle' # Otherwise getMsg retuns 'Runden Sie ihr Ergebnis auf `r ROUND` Nachkommastellen' setMsg(ROUND='Runden Sie ihr Ergebnis auf `r ROUND` Nachkommastellen', '0'='Runden Sie ihr Ergebnis auf eine ganze Zahl', '1'='Runden Sie ihr Ergebnis auf eine Nachkommastelle') getMsg(ROUND=0, .lang="de", .domain="round") getMsg(ROUND=1, .lang="de", .domain="round") getMsg(ROUND=2, .lang="de", .domain="round")