Keyword

K2 on multilanguage sites

  • Filip Nikitovic
  • Filip Nikitovic's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 4 months ago #113446 by Filip Nikitovic
Replied by Filip Nikitovic on topic Re: K2 on multilanguage sites
Thank You.

Just to check , if I change item.php as You told me then facebook "like" button will be in german on german pages and in english language on english pages.
Is that correct?

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
11 years 4 months ago #113447 by Yiota
Replied by Yiota on topic Re: K2 on multilanguage sites
Don't forget to make an if statement and check the language.
Try this:

$lang = JFactory::getLanguage();
$locale = $lang->getTag();

if ($locale=='de-DE'):
include the facebook button with the change I suggested for the script block;
else :
leave the default facebook button code.
endif;

Please Log in or Create an account to join the conversation.

More
11 years 4 months ago #113448 by Jo
Replied by Jo on topic Re: K2 on multilanguage sites
Hi,

I am also trying to get this to work!

The Twitter button changes automatically into other languages but I cannot get the facebook text to change.

I must be putting in the the code wrong :blush:

Any help appreciated!

Please Log in or Create an account to join the conversation.

More
11 years 4 months ago - 11 years 4 months ago #113449 by Jo
Replied by Jo on topic Re: K2 on multilanguage sites
WOOHOOO!

Finally got it to work. Thank you Yiota for pointing me in the right direction.

I hope this helps someone else.

NOTE: This is for a 4 language site with spanish being the default language and catalan, english and french as the other languages so you will have to alter language codes and remove the blocks that you don't want. the default language is in the last block after the <?php else: ?>

First I added

$lang = JFactory::getLanguage();
$locale = $lang->getTag();

Right under
defined('_JEXEC') or die;

near the top of item.php

Then find the code between

<div id="fb-root"></div>
and
<div class="fb-like" data-send="false" data-width="200" data-show-faces="true"></div>

at around line 320 and replace the code with this



<?php if ($locale=='es-ES'): ?>
<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/es_ES/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php endif; ?>
<?php if ($locale=='ca-ES'): ?>
<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/ca_ES/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php endif; ?>
<?php if ($locale=='fr-FR'): ?>
<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/fr_FR/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

<?php else: ?>
<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/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php endif; ?>


I don't know if this is the correct way to do it but it works!

Please Log in or Create an account to join the conversation.

  • Filip Nikitovic
  • Filip Nikitovic's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 4 months ago #113450 by Filip Nikitovic
Replied by Filip Nikitovic on topic Re: K2 on multilanguage sites
I tried the same thing but it doesnt work.

Can You please paste Your item.php code here,just code between <!-- Facebook Button --> and <!-- Google +1 Button -->

It would help me a lot.

Please Log in or Create an account to join the conversation.

  • Filip Nikitovic
  • Filip Nikitovic's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 4 months ago - 11 years 4 months ago #113451 by Filip Nikitovic
Replied by Filip Nikitovic on topic Re: K2 on multilanguage sites
This is where I inserted

$lang = JFactory::getLanguage();
$locale = $lang->getTag();
<?php
/**
 * @version             $Id: item.php 1812 2013-01-14 18:45:06Z lefteris.kavadas $
 * @package             K2
 * @author              JoomlaWorks https://www.joomlaworks.net
 * @copyright   Copyright (c) 2006 - 2013 JoomlaWorks Ltd. All rights reserved.
 * @license             GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */

// no direct access
defined('_JEXEC') or die;
$lang = JFactory::getLanguage(); 
$locale = $lang->getTag(); 
?>

Just as You did

Please Log in or Create an account to join the conversation.

  • Filip Nikitovic
  • Filip Nikitovic's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 4 months ago - 11 years 4 months ago #113452 by Filip Nikitovic
Replied by Filip Nikitovic on topic Re: K2 on multilanguage sites
<!-- Facebook Button -->
<div class="itemFacebookButton">
   <div id="fb-root"></div>
   <?php if ($locale=='de_DE'): ?> 
<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/de_DE/all.js#xfbml=1"; 
fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 
</script> 
<?php else: ?> 
<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/en_US/all.js#xfbml=1"; 
fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 
</script> 
<?php endif; ?>                   
  <div class="fb-like" data-send="false" data-width="200" data-show-faces="true"></div>
   </div>
   <?php endif; ?>

Mybe You can see here what I did wrong

Please Log in or Create an account to join the conversation.

More
11 years 4 months ago #113453 by Jo
Replied by Jo on topic Re: K2 on multilanguage sites
Looks ok,
Are you sure you have added the languages in the content section of the language manager?

Please Log in or Create an account to join the conversation.

  • Yiota
  • Yiota's Avatar
  • Visitor
11 years 4 months ago #113454 by Yiota
Replied by Yiota on topic Re: K2 on multilanguage sites
The $locale of any language is not with an underscore put with a dash. What I mean is that instead of $locale=='de_DE' you should have $locale=='de-DE'.

Please Log in or Create an account to join the conversation.

  • Filip Nikitovic
  • Filip Nikitovic's Avatar Topic Author
  • Offline
  • Senior Member
More
11 years 4 months ago #113455 by Filip Nikitovic
Replied by Filip Nikitovic on topic Re: K2 on multilanguage sites
Hi,
Can be this done also for google+ button?

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum