wikimedia / jquery.i18n

🌐 jQuery based internationalization library
GNU General Public License v2.0
699 stars 143 forks source link

HTML elements are escaped #90

Open jphblais opened 8 years ago

jphblais commented 8 years ago

I have a message containing and HTML element like "test
text", but my "br" is displayed as escaped element. How to avoid elements escaping? I'm using the transparent $('[data-i18n]').i18n(); technique to translate all the content in my single page app.

ricordisamoa commented 8 years ago

https://github.com/wikimedia/jquery.i18n/blob/master/README.md#data-api

$.fn.i18n is always about replacing text of the element. If you want to change the html of the element, you may want to use: $(selector).html($.i18n(messagekey))

jphblais commented 8 years ago

Thank you for your fast answer. For other, here is how I resolved it:

    function doI18n() {
        var elements = $('[data-i18n]');
        elements.each(function(index, value) {
            var messageKey = $(value).attr('data-i18n');
            var txt = $.i18n(messageKey);
            $(elements[index]).html(txt);
        });
    }
smalyshev commented 8 years ago

See also proposed pull: https://github.com/wikimedia/jquery.i18n/pull/112