coderifous / jquery-localize

a jQuery plugin that makes it easy to internationalize your web site.
465 stars 142 forks source link

Localizing element attributes #7

Closed yohanb closed 13 years ago

yohanb commented 13 years ago

Hi, Instead of deciding which attribute to localize depending on the type of element (i.e. alt and src attributes for image), why don't you add the possibility to assign localized text to any attribute value? For example:

Problem: localize div title attribute

Possible solution:

The code change for the plugin is easy (in the callback): var elem, key, value, attr; elem = $(this); key = elem.attr("rel").match(/localize[(.?)]/)[1]; attr = elem.attr("rel").match(/attr[(.?)]/); value = valueForKey(key, data); if (attr != null) { return elem.attr(attr[1], value); } else if ...

What do you think?

Yohan

coderifous commented 13 years ago

Yohan - It's a good idea, but I'm not sure what I'd want the implementation to be. I'll have to give it some thought. In the mean time, some real world use cases and a pull-request with changes that are tested and backward compatible would go a long way. Do you know coffeescript? :)

yohanb commented 13 years ago

Don't know coffeescript but I can sure learn! I can't do a pull request on github... do I need special permissions? Btw, with the oncoming official localization plugin from Microsoft, do you think your efforts are still worth it?

coderifous commented 13 years ago

I haven't really looked at the microsoft plugin much, but a quick glance at https://github.com/jquery/globalize#generating says that some things require Windows and dot-Net. Thanks, but no thanks.

Also, for all that README, I couldn't find any obvious instructions as to how I might use it on a site. For instance, jquery-localize will automatically detect the language, download the language pack (json file), and apply the translations to the page. It looks like the globalize plugin might be more thoughtful on the side of supporting date and currency formats, but otherwise leaves plenty of work for the developer to implement. I could potentially see a case for jquery-localize to make use of globalize, but I'd have to understand it more before making that call.

coderifous commented 13 years ago

RE the pull-request question: http://help.github.com/send-pull-requests/

yohanb commented 13 years ago

Hehe I thought the same thing when I read through the documentation for the Microsoft plugin... "how do I get started?!". Thanks for the information.

panurge-ws commented 11 years ago

Hello, this could be a very handy feature. I have edited the code proposed by yohanb with the html5 data attribute:

var elem, key, value, attr; elem = $(this); key = elem.data("localize"); key || (key = elem.attr("rel").match(/localize[(.*?)]/)[1]); attr = elem.data("localize_attr"); value = valueForKey(key, data); if (attr != null) { return elem.attr(attr, value); } return localizeElement(elem, key, value);

Possible use: