jquery.i18n icon indicating copy to clipboard operation
jquery.i18n copied to clipboard

data-i18n on tag attributes

Open adamwight opened this issue 12 years ago • 7 comments

I don't know how to solve this problem: How would you use the transparent technique, $('[data-i18n]').i18n(), to localize an element attribute such as <input value="msgname" ,,, ?

adamwight avatar May 10 '13 22:05 adamwight

Such as what? You probably wrote and HTML element and GitHub deleted it.

amire80 avatar May 11 '13 05:05 amire80

Thanks for noticing that! My example was, <input value="msgname" ,,,

adamwight avatar May 11 '13 06:05 adamwight

It is not possible right now to localize the element attributes. You will need to use $('inputselector').val() or attr() methods to achieve this.

If you feel that it is a desirable feature, please file an enhancement bug. Atleast for the value attributes of input tags, I think it is a nice to have feature

santhoshtr avatar May 11 '13 12:05 santhoshtr

It would be really nice if we could search for attributes named like "data-i18n-value", which would cause the attribute "value" on this element to be overwritten with a translated message. Unfortunately, I don't think there's an efficient way to search for an attribute name prefix.

What do you think about an extended syntax for the "data-i18n" attribute, something like: <input value="en fallback" data-18n="{'value': 'msg-key-fubar'}" ... or possibly the attributes should be a level deeper, to leave flexibility for other stuff: {'translate-attributes': {'value': 'msg-fubar' ...

The ability to annotate elements with this information directly is definitely a nice to have feature. Currently, I am generating elements with a template language and keeping element metadata self-contained greatly reduces code complexity.

adamwight avatar May 19 '13 16:05 adamwight

P.S. i cannot add the "enhancement" label. Maybe the project permissions do not allow it?

adamwight avatar May 19 '13 16:05 adamwight

seconded, this would be very nice.

willbonney avatar May 31 '16 08:05 willbonney

Proposed patch: https://github.com/wikimedia/jquery.i18n/pull/112 (covers one attribute for now, but can be easily extended for multiple ones I assume)

smalyshev avatar Aug 10 '16 05:08 smalyshev