PHP code-link to the home page for multi language web site
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.
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.
-
- 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
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.
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.
- imanickam
- 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
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
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged
-
- 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
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.
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.
-
- 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
On this moment I found solution like this:
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?
Code: Select all
<?php
$lang = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages('lang_code');
$languageCode = $languages[ $lang->getTag() ]->sef;
?>
<a href="<?php echo '/' . $languageCode . '/' ; ?>">SomeText</a>
May be exists another solution, something like "$this->baseurl" but which works properly for multilingual web site?
- imanickam
- 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
It is a simpler code. As long as it works, you could use it.
You could try the following line of code:
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.
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;
}
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
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged
-
- 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
Thanks. Your code works fine and I will use it, but your code will not work until add In what version of Joomla this issue will be fixed: 3.4.4 , 3.5, 4 ?
Code: Select all
$app = JFactory::getApplication();
- infograf768
- 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
You can use the corrected file until 3.4.4 is out.
ROOT/plugins/system/languagefilter/
to replace languagefilter.php
Then use $this->baseurl
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
---------------------------------
ex-Joomla Translation Coordination Team • ex-Joomla! Production Working Group
- imanickam
- 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
Good Point.huligan wrote:Your code works fine and I will use it, but your code will not work until addCode: Select all
$app = JFactory::getApplication();
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
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged
-
- 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
I just have tried to use attached file and have made some interesting decisions, but at first I need to write some pre text.infograf768 wrote:You can use the corrected file until 3.4.4 is out.Decompress it in
ROOT/plugins/system/languagefilter/
to replace languagefilter.php
Then use $this->baseurl
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...