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

Why data() not attr() #172

Open
ivanromakh opened this issue Jul 25, 2018 · 4 comments
Open

Why data() not attr() #172

ivanromakh opened this issue Jul 25, 2018 · 4 comments

Comments

@ivanromakh
Copy link

ivanromakh commented Jul 25, 2018

I have a little problem here
https://github.com/wikimedia/jquery.i18n/blob/master/src/jquery.i18n.js#L230

For case of using data-bind="attr: {data-i18n: somevar}"

  1. attr updated
  2. data not updated

And in the end if I change somevar translation will not changed in my page.
Maybe this is problem of data-bind. I don`t know.
I added class and update data before each translation with next script:

for (let i =0; i < elements.length; i++) {
$(element).data('i18n', $(element).attr('data-i18n'));
}

$('[data-i18n]').i18n();

@ivanromakh
Copy link
Author

I think you should add check for attributes too:)
Thanks:)

@benno-meyer
Copy link

I have the same problem. How did you solve it?

@aromakh
Copy link

aromakh commented Oct 31, 2018

@benno-meyer Set attr and then data. Or set data and then attr, don`t remember. So need two operations instead of one.

@bennomeyer
Copy link

bennomeyer commented Oct 31, 2018

Ah, I see.
You have to first change the variable with $(element).attr('data-i18n', new_var);
and then refresh the data storage with the new variable $(element).data('i18n', $(element).attr('data-i18n'));

Thank you so much for your help!

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

4 participants