shiny.i18n appears to not handle backslash properly
Opened this issue · 4 comments
I'm using shiny.i18n to create multilang PDFs with knitr and LaTeX.
Using double-backslash for markup in i18n-translated strings results in the key not being recognized anymore.
Example:
i18n$t("One \\& Two")
1: In private$raw_translate(keyword) :
'One \& Two' translation does not exist.
translate-de.csv:
en,de
"One \\& Two","Eins \\& Zwei"
Indeed, after reading this:
en,de
"One \\& Two","Eins \\& Zwei"
You get:
> i18n$get_translations()
de
One \\\\& Two Eins \\\\& Zwei
That's something to do with how read.csv
handles backslash and special characters probably.
This worked fine for me though:
en,de
"One & Two","Eins & Zwei"
Hey @dokato, thanks for the fast reply.
I have no idea what happens. So I need \\
in R to output LaTeX commands, such as \textbf{}
. Now with i18n$t("\\textbf{bold face text}")
this works. Adding the translation and stripping the second backslash appears to work as well, both to have it matching the key and even for the target language I only need one backslash, which gets correctly entered in the .tex file.
This seems strange to me. But, oh well. If it works I just need to strip the second backslash after extracting the keys.
So I think that you need to keep double backslash only in R strings, otherwise it interprets by default it as a beginning of special character, e.g.
> cat("\ta")
a
> cat("\\ta")
\ta
I remembered that I had this problem in my other project, where we were porting template to latex (https://github.com/satRdays/badgeR/).
Alright, I had to use sed to remove the second backslash. But now translations work well enough.
Maybe create_translation_file() could do this for us? ;-)