PHP code-link to the home page for multi language web site

General questions regarding the use of languages in Joomla! 3.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
huligan
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jul 27, 2015 3:19 pm
Location: Ukraine, Kyiv

PHP code-link to the home page for multi language web site

Post by huligan » Mon Jul 27, 2015 3:33 pm

Hi,

I am building a multi language web site and want to use Logo link to main page.
Links with href: "/", "index.php", $this->baseurl, etc. don't work properly.
I am using ru and en languages. And each time logo link redirects me to the ru home page, even if I switch language to en.
I also have link to the main page (home page) in menu and it works properly.
What code should I write to get correct link to the main page with correct default language? Correct default language it is a language that is shown to the user while viewing the web site.

Thanks for help.

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28204
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: PHP code-link to the home page for multi language web si

Post by imanickam » Tue Jul 28, 2015 3:05 am

I believe that the issue could be attributed to an issue with the plug-in "System - Lanugage Filter". Suggest reviewing https://github.com/joomla/joomla-cms/pull/7427.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

huligan
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jul 27, 2015 3:19 pm
Location: Ukraine, Kyiv

Re: PHP code-link to the home page for multi language web si

Post by huligan » Tue Jul 28, 2015 9:57 am

Additional info:
1) I am using K2 and when I turn off SEF I see web site home link "/index.php?lang=ru". When I switch language to English I see home link "/index.php?option=com_k2&view=itemlist&layout=category&Itemid=215&lang=en". PHP code $this->baseurl send me to "/index.php?lang=ru" web page.

2) When I turn off SEF home link is "/index.php/ru/", and when I switch lang the home link is "/index.php/en/". PHP code "$this->baseurl" sends me to "/index.php/ru/" web page.

For me it is OK that lang is present in URL, I just want to build a link, that sends me to a home page, depending on chosen lang.

huligan
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jul 27, 2015 3:19 pm
Location: Ukraine, Kyiv

Re: PHP code-link to the home page for multi language web si

Post by huligan » Tue Jul 28, 2015 10:57 am

On this moment I found solution like this:

Code: Select all

<?php 
 $lang = JFactory::getLanguage();
 $languages = JLanguageHelper::getLanguages('lang_code');
 $languageCode = $languages[ $lang->getTag() ]->sef;
?>
<a href="<?php echo '/' . $languageCode . '/' ; ?>">SomeText</a>
But it is a "HardCoding" and it works only if SEF and URL Redirections are turned on.
May be exists another solution, something like "$this->baseurl" but which works properly for multilingual web site?

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28204
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: PHP code-link to the home page for multi language web si

Post by imanickam » Tue Jul 28, 2015 1:37 pm

It is a simpler code. As long as it works, you could use it.

You could try the following line of code:

Code: Select all

if (JLanguageMultilang::isEnabled())
{
	$homemenu	= $app->getMenu()->getDefault(JFactory::getLanguage()->getTag());
	$logo_link	= JRoute::_('index.php?Itemid=' . $homemenu->id);
}
else
{
	$logo_link = $this->baseurl;
}
In fact, you could consider any code you are inserting now as a temporary solution. Once the next version of Joomla! released, the plugin "System - Language Filter" is fixed, the following line of code should work.

Code: Select all

<a href="<?php echo $this->baseurl; ?>/"
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

huligan
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jul 27, 2015 3:19 pm
Location: Ukraine, Kyiv

Re: PHP code-link to the home page for multi language web si

Post by huligan » Tue Jul 28, 2015 3:25 pm

Thanks. Your code works fine and I will use it, but your code will not work until add

Code: Select all

$app = JFactory::getApplication();
In what version of Joomla this issue will be fixed: 3.4.4 , 3.5, 4 ?

User avatar
infograf768
Joomla! Master
Joomla! Master
Posts: 19133
Joined: Fri Aug 12, 2005 3:47 pm
Location: **Translation Matters**

Re: PHP code-link to the home page for multi language web si

Post by infograf768 » Tue Jul 28, 2015 3:37 pm

You can use the corrected file until 3.4.4 is out.
languagefilter.php.zip
Decompress it in
ROOT/plugins/system/languagefilter/
to replace languagefilter.php

Then use $this->baseurl
You do not have the required permissions to view the files attached to this post.
Jean-Marie Simonet / infograf
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28204
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: PHP code-link to the home page for multi language web si

Post by imanickam » Tue Jul 28, 2015 4:16 pm

huligan wrote:Your code works fine and I will use it, but your code will not work until add

Code: Select all

$app = JFactory::getApplication();
Good Point.

I overlooked that point as this code is present in the beginning of the template Protostar.

In fact, this code snippet was written by infograf768 when we were testing the logo link for a multilingual site. After this only, it was found out by infograf768 that the issue is really in the plugin.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged

huligan
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Mon Jul 27, 2015 3:19 pm
Location: Ukraine, Kyiv

Re: PHP code-link to the home page for multi language web si

Post by huligan » Wed Jul 29, 2015 10:03 am

infograf768 wrote:You can use the corrected file until 3.4.4 is out.
languagefilter.php.zip
Decompress it in
ROOT/plugins/system/languagefilter/
to replace languagefilter.php

Then use $this->baseurl
I just have tried to use attached file and have made some interesting decisions, but at first I need to write some pre text.

I am using custom template)not stock) and at the beginning logo link had href="./" path in this template. It didn't work for multilingual web site, it sent user to the main page with one language, not the same language that was chosen.
$this->baseurl also didn't work and I found the solution using code examples in this subject.
After updating "languagefilter.php" file with attached file, code "$this->basurl" doesn't work. It shows empty string and I don't know why. But good news is that href="./" path now working properly :) So, now I just using "./" path in my code. Thank you. Of course it is interesting why "$this->basurl" doesn't work after updating the file, but it seems to me that it is another subject...


Locked

Return to “Language - Joomla! 3.x”