Meyer
Meyer

Reputation: 67

Strings containing an accent do not appear

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ó) 

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

Answers (1)

Tonio Liebrand
Tonio Liebrand

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

Related Questions