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

Could you update jquery.i18n.parser.js on line 33 for $ problem #218

Open
BG-Kim opened this issue Jul 27, 2020 · 4 comments
Open

Could you update jquery.i18n.parser.js on line 33 for $ problem #218

BG-Kim opened this issue Jul 27, 2020 · 4 comments

Comments

@BG-Kim
Copy link

BG-Kim commented Jul 27, 2020

HTML
<div data-i18n="HOME_FOO"></div>

JSON en
"HOME_FOO" : "Give me $2"

This is make warning follows :
jQuery.Deferred exception: Cannot read property '1' of undefined TypeError: Cannot read property '1' of undefined

Problem is jquery.i18n.parser.js simpleParse() on line 33

return parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;
=>
return parameters && parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;
or
return parameters !== undefined && parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;

I guess missing to check parameter also undefined or not.

Thank you.

@santhoshtr
Copy link
Member

In your message, where is $1? Jquery.i18n assumes placeholders in its linear order. So of you have a placeholder value "10", that is 1st placeholder indicated by $1. It does not make sense to assume it as $2.

This is the reason for the assumption of $1 in parameters array. If I add extra checks there, I am afraid it will break in other places because this isa fundamental assumption about message parameters.

@BG-Kim
Copy link
Author

BG-Kim commented Jul 29, 2020

@santhoshtr :
Hello, I want to write symbol '$' itself. That is not variable.

I want to write the message ‘’Korean Grandma Living On $2 A Day”.
But, It made a warning with a similar error level.

I try \\$ But It’s not work.
So, I open code and fix it.

PS. You know, Normally language file is written by not a programmer.
And a special symbol can make errors. It’s a problem.

@mooeypoo
Copy link
Member

@BG-Kim using the $ sign as-is inside the message would confuse the assumptions made in the system regarding variables, and as @santhoshtr points out, it's not very safe to undo this assumption.

Instead, you can use the HTML code for the $ sign (&#36;) in your message, which would render in HTML as the sign without resembling a variable. From your example, your message can be Korean Grandma Living On &#36;2 A Day which would render (even in this reply box) as "Korean Grandma Living On $2 A Day"

@BG-Kim
Copy link
Author

BG-Kim commented Jul 30, 2020

@santhoshtr @mooeypoo

Hum… I think null and undefined checks are more written solid code.
So, I guess the author missed it.
Obviously, below code has danger when parameters is null or undefined.

return parameters[ index ] !== undefined ? parameters[ index ] : '$' + match;

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

No branches or pull requests

3 participants