• 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 the bread_crumb call in header.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.

    http://wordpress.org/extend/plugins/012-ps-multi-languages/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Wang Bin

    (@ouhinit)

    Hello

    We were able in this way, please try.

    <iframe src="http://www.facebook.com/plugins/like.php?locale=<?php echo $selang; ?>&href=http://www.test.net&layout=button_count&show_faces=false&width=100&action=like&font&colorscheme=light&height=21" scrolling="n    o" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px; " allowTransparency="true">
    </iframe>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

    Plugin Author Wang Bin

    (@ouhinit)

    I think you should check the var_dump the $ selang, whether or not the value is good matches.

    Thread Starter amonti

    (@amonti)

    Wang; thanks for writing the plug-in – the admin interface is great! I’ll have to try the iframe code as well; I’ll also var_dump $selang to make sure it’s the right type.

    I also added code to append: “&lang=’ to the end of the Twitter and Facebook parameters to make sure that links are sent using the users’ selected language. The code is really easy:

    Twitter:

    data-url="<?php printf('%s&lang=%s',the_permalink(),get_load_language()); ?>"

    Facebook:

    href="<?php printf('%s&lang=%s',the_permalink(),get_load_language()); ?>"

    I should create another thread for the following question, but I’ll ask you here:

    Is there any chance that you can figure out a way to only display comments for a particular language?

    I’m stuck where everyone else who have tackled the problem seems to be: I can store language metadata with the comment and can filter the comments based on language, but the comment counts and comment page functionality only consider ALL comments – not just comments for a particular language.

    So for example, if a German user looks at a post, it says that there are 3 comments, but because they are all in English, no comments appear. If there are enough filtered comments, “Next” appears, even though there aren’t any comments displayed! Comment count processing seems to be buried deep in the query and comment classes.

    If there’s enough interest, I’ll create a separate thread.

    Any suggestions would be appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: 012 Ps Multi Languages] Facebook Localization’ is closed to new replies.