-
-
Notifications
You must be signed in to change notification settings - Fork 629
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected interpolation within variables #1487
Comments
adrai
added a commit
that referenced
this issue
Jul 15, 2020
adrai
added a commit
that referenced
this issue
Jul 15, 2020
* extend usage of skipOnVariables, should fix #1487
thank you, fixed with skipOnVariables in v19.6.1 |
If you like this module don鈥檛 forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project. There are many ways to help this project 馃檹 |
Thank you for the very quick fix! Unfortunately now I encountered another issue which is kind of related, at #1490. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
馃悰 Bug Report
During interpolation of variables, i18next also performs interpolation within the contents of the variables. I would not expect the variables to also be affected by interpolation, as the contents of them might not be from a trusted source (user input). At least there should be an option to disable this (which in my opinion should be the default in a future version).
I don't really understand why it would be desirable to use variables within variables, as developers can just inline the variables themselves instead of relying on i18next to derefence them.
An additional side effect of the interpolation within variables (and this side effect actually led me to find out about this issue) is that it makes it impossible to render double curly braces in a translated text. I have my own template engine in my application that also uses double braces for placeholders, and I wanted an introductory paragraph to explain how the user can use the placeholders, which required me to inline double braces within the text. But I did not find any way documented on how the double braces could be escaped, so I tried adding them through a variable, only to realize that the contents of the variable will also have interpolation applied (which leads to the removal of the "placeholder").
To Reproduce
See this codesandbox.
Or to reproduce:
example: "Example Placeholder: {{examplePlaceholder}}"
const result = t("example", { examplePlaceholder: "{{ThisShouldNotGetParsed}}" })
Expected behavior
I would expect the result to contain the string:
"Example Placeholder: {{ThisShouldNotGetParsed}}"
. However, the current i18next implementation would result in a string like this:"Example Placeholder: "
(Because it tries to resolve{{ThisShouldNotGetParsed}}
but is unable to, as there is no such variable. It even prints a warning in debug mode saying that the variable ThisShouldNotGetParsed is not set)I also enabled the new
skipOnVariables
option as well as disabling escaping of values (withescapeValue: false
in the interpolation options). Both did not change the result.Your Environment
The text was updated successfully, but these errors were encountered: