Different URL keys for different language CMS pages
Asked Answered
N

3

6

I'm currently setting up a Magento shop that will support a few different languages.

One issue that I ran into is that I can't find out how to link two CMS pages together, so that when a user switches their language, they are automatically forwarded to the current CMS page but in their preferred language. One option would be to use the same URL key for both pages, but that wouldn't be very user friendly as some users would then see URL keys not in their native language.

Let me give you an example:

I have an "About us" page. In the English version of the store, the URL of that page is /about-us. Now a German user lands on that page and switches his language. But because the German equivalent to "About us" is "Über uns", the German version of that page is at /ueber-uns, so the user would be presented a 404 page because no German version of /about-us exists.

Does anybody know how to solve this issue?

Update: Did some more research and found nothing. I can't believe I am the only one with this problem? The go-to solution, using the same URL key for all languages, seems very ugly and not very user friendly!

Nev answered 12/6, 2013 at 18:47 Comment(0)
N
10

So, the only solution that I found was to manually create a redirect for each page in the Magento Rewrite Rules. Do do that, go to Catalog -> URL Rewrite Management and add each page in the following format:

enter image description here

So if a user is using the Francais store view and requests /url-in-english, the redirect will kick in and redirect the user to /url-in-french.

This is of course not an ideal solution, it would be preferred if two pages could be "linked" directly, but I suppose I will have to use this for the moment. If anybody comes up with a better solution feel free to add yours!

Nev answered 17/6, 2013 at 11:25 Comment(1)
Your image is worth a thousand words, hehehe. My translation package (pt_br) was inverting the target path and request path in the admin and I didn't know why it wasn't working. Thanks for sharing with images. :)Reynoso
H
3

I have seen this bug in Magento CE 1.8.0.0. The problem here was a wrong assignment in \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php.

To solve this problem it is sufficient to change the assignment of $fromStore in the protected function _rewriteDb() within the Mage_Core_Model_Url_Rewrite_Request class from

$fromStore = $this->_request->getQuery('___from_store');

to

$fromStore = Mage::getModel('core/store')->load($this->_request->getQuery('___from_store'), 'code')->getId();

with the result that we can access the $stores array with the right key (with the store id instead of the store code). With this the if statement

 if (!empty($stores[$fromStore])) {

works in the right way.

As a reminder: Do not modify core files. Just copy \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php to \app\code\local\Mage\Core\Model\Url\Rewrite\Request.php before any change. You will find this answer in German here: Rewrite von Seiten in verschiedenen Sprachen und verschiedenen URL Keys in Magento

Hausa answered 5/9, 2015 at 19:1 Comment(0)
J
0

Above solution works but takes a while. We just did the following to rewrite the language changer url when on a cms page to go to the base url:

Add the following code to app/design/frontend/default/template_name/template/page/switch/languages.html after the part where the $url variable is filled (on our it was like

$url = /*explode( '?',*/$_lang->getCurrentUrl()/*);*/;

so we added the following:

if(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.com/')){$url = strstr($url, '.com/', true) . '.com/';}
elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.de/')){$url = strstr($url, '.de/', true) . '.de/';}
elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.nl/')){$url = strstr($url, '.nl/', true) . '.nl/';}

What I did here is check if on a cms page and check if the url contains either .com/ ; .de/ or .nl and strip the part before then add the domain extension back.

in our example: http://www.mega-watch.com/about-us?blabla will become http://www.mega-watch.com/

Hope this helps someone out..

Junitajunius answered 1/11, 2013 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.