Reputation: 67
I'm currently building a shiny application that needs to be translated in different languages. I have the whole structure but I'm struggling into getting values such as "Validació" that contain accents.
The structure I've followed is the following:
key, cat, en "selecció", "selecció", "Selection" "Diferències","Diferències", "Differences" "Descarregar","Descarregar", "Download" "Diagnòstics","Diagnòstics", "Diagnoses"
Code:
tr <- function(text){
sapply(text, function(s) translation[[s]][["cat"]], USE.NAMES=F)
}
When I translate something, since I am doing in another file, I assign it to another variable something like:
str_seleccio <- tr('Selecció)
'Selecció'
would be according to this function, tr('Selecció')
and provides a correct answer if I execute it in the RStudio terminal but when I do it in the Shiny application, appears to me as a NULL
. If the word I translate has no accents such as "Hello", tr("Hello")
provides me a correct answer in the Shiny application and I can see it throught the code.So mainly tr(word) gets the correct value but when assigning it "loses the value" so I'm a bit lost how to do it.
I know that you can do something like Encoding(str_seleccio) <- "UTF-8"
but in this case is not working. In case of plain words it used to do but since when I asssign it, gets NULL
is not working.
Any idea? Any suggestion? What I would like is to add something to tr function
The main idea comes from this repository that if you can take a look is the simplest version you can do, but (s)he has problem with utf-8 also.
https://github.com/chrislad/multilingualShinyApp
Upvotes: 3
Views: 626
Reputation: 17689
As in http://shiny.rstudio.com/articles/unicode.html suggested (re)save all files with UTF-8 encoding.
Additionaly change within updateTranslation.R
:
translationContent <- read.delim("dictionary.csv", header = TRUE, sep = "\t", as.is = TRUE)
to:
translationContent <- read.delim("dictionary.csv", header = TRUE, sep = "\t", as.is = TRUE, fileEncoding = "UTF-8")
.
Warning, when you (re)save ui.R, your "c-cedilla" might get destroyed. Just re-insert it, in case it happens.
Happy easter :)
Upvotes: 1