jquery.i18n
jquery.i18n copied to clipboard
data-i18n on tag attributes
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" ,,, ?
Such as what? You probably wrote and HTML element and GitHub deleted it.
Thanks for noticing that! My example was, <input value="msgname" ,,,
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
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.
P.S. i cannot add the "enhancement" label. Maybe the project permissions do not allow it?
seconded, this would be very nice.
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)