0

After trying a lot of extensions, I've ended up uninstalling all the extensions and add the social buttons by myself via code.

Apparently I managed to create the buttons correctly (altough the Facebook button takes a HUGE amount of sec. to load) but I'm struggling to have these buttons automatically trnaslated in other language.

My website has 2 languages (and store views), but I can not find how to swap the button text and the social popup content for sharing automatically.

So, now the trouble is:

I have the FB "like" button in Italian, when I change store view for English I still have the FB "like" button (and the content of the FB box for sharing the product) in Italian.

Is it possible to change this?

This is the code inside the file "view.phtml":

 <div id="facebook_like_product_button"><fb:like ref="product_page" layout="button_count" show_faces="false" colorscheme="light" width="500"></fb:like></div>

<!-- Facebook Like Product Button BEGIN - load the SDK asynchronously -->
    <div id="fb-root"></div>
        <script>
        /* <![CDATA[ */
            window.fbAsyncInit = function() {
            FB.init({appId: '1386792571543845', status: true, cookie: true,
                xfbml: true});
        };
        (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol +
            '//connect.facebook.net/<?php echo $this->__('it_IT') ?>/all.js';
            document.getElementById('fb-root').appendChild(e);
        }());
         /* ]]> */
        </script>
<!-- Facebook Like Product Button END -->

I tried to replace

<?php echo $this->__('it_IT') ?>

with :

<?php echo $this->getLang() ?>

But the fb button disappears.

1

I would first create a custom block, for example:

<?php

class Company_Module_Block_Facebook extends Mage_Core_Block_Template
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('company/module/facebook.phtml');
    }

    public function getScheme()
    {
        return Mage::app()->getStore()->isCurrentlySecure() ? 'https:' : 'http:';
    }

    public function getLocale()
    {
        return Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE);
    }
}

And in company/module/facebook.phtml template:

<div id="facebook_like_product_button"><fb:like ref="product_page" layout="button_count" show_faces="false" colorscheme="light" width="500"></fb:like></div>

<!-- Facebook Like Product Button BEGIN - load the SDK asynchronously -->
<div id="fb-root"></div>
<script>
    /* <![CDATA[ */
    window.fbAsyncInit = function() {
        FB.init({appId: '1386792571543845', status: true, cookie: true,
            xfbml: true});
    };
    (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol + '<?php echo $this->getScheme() ?>' +
        '//connect.facebook.net/<?php echo $this->getLocale() ?>/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
    /* ]]> */
</script>
<!-- Facebook Like Product Button END -->

You can then insert your block via layout update.

  • thank you ! Just one last question: assuming my lack of knowledge in magento there is another simplier way to do that? I know that editing the code is nto a "best practice" and will have collateral effects during magento updates, but if I do not need (or want ) to update , what could be the fastest way? If I simply modify my code in the view.phtml page using :<?php echo $this->getLocale() ?> insted of <?php echo $this->__('it_IT') ?> what should I add more? and in what file? thank you very much and please excuse me for the bother. – giancarlo Jan 6 '15 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.