i18next-parser
i18next-parser copied to clipboard
Handlebars lexer escapeValue defaultValue with HTML content
🐛 Bug Report
I parsed my .hbs files and use defaultValue. In one, I need to add a link with text as defaultValue. For example :
{{__ "animations:lead" interpolate='{\"escapeValue\":false}' defaultValue='Lorem ipsum <a target="_blank" href="https://github.com/i18next/i18next-parser">https://github.com/i18next/i18next-parser</a>' }}
The HTML content in defaultValue is not parsed, the value in the JSON file will be empty.
So it seem that interpolate is not take into account ?
But event if I escape the content myself,
Lorem ipsum <a target="_blank" href="https://github.com/i18next/i18next-parser">https://github.com/i18next/i18next-parser</a>
the defaultValue will be empty. From my tests it seem that it's related to the =
character.
Expected behavior
-
Allow to use interpolate as described here https://www.i18next.com/translation-function/interpolation
-
Allow to pass HTML as defaultValue
Your Environment
- runtime version: i.e. node v12.16.1 -i18next version: i.e. ^4.2.0
- os: Mac
@imike57 The issue is not related to interpolation. You have an html tag in the default value and that's why it is not properly parsed. I have not time to investigate this but you are welcome to open a PR. The Handlebar lexer should probably be rewritten not to use regexes as this is not a simple fix.
For future reference, here is a failing test case:
it('extracts the defaultValue arguments with html', (done) => {
const Lexer = new HandlebarsLexer()
const content = '<p>{{t "first" defaultValue="bla <a href=\"\">bla</a>"}}</p>'
assert.deepEqual(Lexer.extract(content), [
{ key: 'first', defaultValue: 'bla <a href="">bla</a>' },
])
done()
})