Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shiny.i18n appears to not handle backslash properly #56

Open
fkroener opened this issue Feb 9, 2021 · 4 comments
Open

shiny.i18n appears to not handle backslash properly #56

fkroener opened this issue Feb 9, 2021 · 4 comments

Comments

@fkroener
Copy link

fkroener commented Feb 9, 2021

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"
@dokato
Copy link
Contributor

dokato commented Feb 9, 2021

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"

@fkroener
Copy link
Author

fkroener commented Feb 9, 2021

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.

@dokato
Copy link
Contributor

dokato commented Feb 9, 2021

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/).

@fkroener
Copy link
Author

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? ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants