Reputation:
I have a page where the english version facebook's like button is loaded by default. I can only manipulate the page with javascript and don't have access to certain things, i.e. facebook script. So, how can I have that like button translated into another language, say spanish? Thanks.
Upvotes: 4
Views: 8178
Reputation: 7673
It's going to be extremely difficult - there isn't a 'nice' way to do it. This is because the like button lives inside an iframe, and you can't access the contents of it from within your page, with javascript or anything else.
You can manipulate the iframe's src
attribute - check the facebook documentation to see if you can pass in a language parameter - something like: &lang=es
on the end of the URL.
Updated - the URL parameter is locale, as in: &locale=es_ES
Upvotes: 5
Reputation: 42099
Others are talking about an iFrame, which I don't see anywhere on my Facebook page. If you can use GreaseMonkey, or are able to access the links via JS, you can use the following:
jQuery:
$('.liketext').html('Something Else')
JavaScript:
function getElementsByClass(_class,_obj,_tag) {
var found = new Array();
if ( _obj == null ) _obj = document;
if ( _tag == null ) _tag = '*';
var els = _obj.getElementsByTagName(_tag);
var pattern = new RegExp("(^|\\s)"+_class+"(\\s|$)");
for (var n=els.length, j = 0; n--; ) {
if ( pattern.test(els[n].className) ) {
found[j] = els[n];
j++;
}
}
return found;
}
var likes = getElementsByClass('liketext',document);
for (var n=likes.length; n--; )
likes[n].innerHTML = "NEW LIKE TEXT";
document.getElementById('<your iFrame ID').contentWindow.document;
window.frames[0]
Example:
var iF = document.getElementById('<your iFrame ID>').contentWindow.document;
// var iF = window.frames[0].document; // alternative to above
var likes = getElementsByClass('liketext',iF);
for (var n=likes.length; n--; )
likes[n].innerHTML = "NEW LIKE TEXT";
Upvotes: 0
Reputation: 7671
The source of the facebook connect javascript is: http://connect.facebook.net/en_US/all.js
just change en_US to the locale you want. en_ES is Spain's locale, and a list of all facebook locales is at http://facebook.com/translations/FacebookLocales.xml
Upvotes: 7