[Plugin: 012 Ps Multi Languages] Facebook Localization
-
It was bothering me that everything on my site was localized except Facebook content, so I decided to localize that as well. I used the XFBML version of Facebook content, since the HTML5 versions don’t seem to accept a locale parameter, and the iFrame versions (although supporting locale), didn’t work well in my site.
First, you have to add a function to
config/functions.php
in the plug-in’s directory:function get_load_multilingual_language( ){ global $ps_multi_languages; if ( $ps_multi_languages ){ $lang = $ps_multi_languages->get_multilingual_code(get_load_language() ); } return $lang; }
I added this right after the
get_load_language
function. Next, I added the following line right after thebread_crumb
call inheader.php
:<?php if ( function_exists( 'get_load_multilingual_language' ) ) $selang = str_replace('-','_', get_load_multilingual_language()); ?>
This retrieves the currently selected locale and converts ‘-‘ to ‘_’ because that’s the only way Facebook accepts locale strings.
Still in the
header.php
, add the following code after the<body>
tag:<script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/<?php echo($selang) ?>/all.js#xfbml=1"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>
Finally, you can add a Facebook button/stream/whatever where you please, and it will be localized. For example:
<fb:subscribe href="https://www.facebook.com/zuck" show_faces="true" width="150"></fb:subscribe>
A complete list of sample buttons and streams is available from Facebook. You can automatically generate the XFBML code for your site by filling in the relevant data and getting the code. Not every language is currently supported.
Note that all of Twitter’s generated code snippets are automatically localized, as long as your site supports localization – no changes required.
Hope this helps – please post if you have any questions. Note that because this modifies
functions.php
, exercise caution when upgrading the plugin – you may have to re-apply your changes.https://www.ads-software.com/extend/plugins/012-ps-multi-languages/
- The topic ‘[Plugin: 012 Ps Multi Languages] Facebook Localization’ is closed to new replies.