[My Solution] Multilanguage supported URLs

Discussion in 'Subrion Open Source CMS Core' started by XCravenX, Oct 24, 2017.

  1. XCravenX

    XCravenX New Member

    Hello everyone,

    First of all i can say i am .net expert and i am not skilled on PHP or Smarty. I wanted to try subrion and i liked it. And then i faced with some problems and one of them was multilanguage supported urls. As i said before, i am not php expert and kinda new on this programming language so i tried to learn something about functions, syntax etc. And then i found decent solution for me but its not eye candy for programming angle.

    --------MY ORIGINAL POST: "How to Hide/Disable/Change menu for per language?"---------

    Hello again,

    CMS doesnt support custom url for multilanguage ( i mean same short url for per language you cannot do /en/shop and /de/geschaft instead of /en/shop and /de/shop). So i was thinkin about if i create 2 pages for shop. Can i hide geschaft menu/page for English language and shop menu/page for German language? I thought i could do it via menu customization page but i can only edit menu name. I cannot put custom url for per language. So hiding should be easier than that. How can i do that, would you like to help to me?
    -------------------------------------------------------------------------------------------------------------------

    ================MY SOLUTION===================================
    First of all we are not goin into hard coding or changing any url rewrite system. We gonna do it as a beginner so my approach was asking questions to myself: Example: "How can i hide/show specific menues for per language?" and then i do some works which listed below;

    1- Create new custom menus with _languagealias(like main_en or main_de) with same position with others. for example: default main menu position is mainmenu and bottom is copyright for kickstarter theme. so i created main_de on mainmenu position and bottom_de on copyright position. I m using them for german language so original ones for english. Now you can create pages for your new menus too. For example old one like if you create page with 2 language ur url will be www.example.com/en/shop and when changed the language it turned to www.example.com/de/shop. It's all about custom url because it's dedicated to one language. So now you have to create another page for other language and chance custom url to something for chosen language. Aftet that put that page into proper menu. for example i did german page and i put it into main_de and bottom_de custom menus.


    2- Now since we have 2x menus for per language we have to pick proper menu from menu list for proper language.

    i placed some code into render-menu.tpl which u can find it in kickstart theme folder.

    ---> For mainmenu position

    {if 'mainmenu' == $position}
    {if {$smarty.const.IA_LANGUAGE} eq 'en' }
    {if 'main' == $menu.name}
    {ia_menu menus=$menu.contents class="nav navbar-nav navbar-right nav-main {$menu.classname}"}
    {/if}
    {else}
    {if 'main_de' == $menu.name}
    {ia_menu menus=$menu.contents class="nav navbar-nav navbar-right nav-main {$menu.classname}"}
    {/if}
    {/if}
    {elseif 'inventory' == $position}

    -----> For bottom menu position

    {elseif 'copyright' == $position}
    {if {$smarty.const.IA_LANGUAGE} eq 'en' }
    {if 'bottom' == $menu.name}
    {ia_menu menus=$menu.contents class="nav-footer {$menu.classname}"}
    {/if}
    {else}
    {if 'bottom_de' == $menu.name}
    {ia_menu menus=$menu.contents class="nav-footer {$menu.classname}"}
    {/if}
    {/if}

    Now we can hide main_de custom mainmenu when chosen language is english and it will show up when chosen language is german.

    3- After that i faced with another problem. If i go into different language url still same only language code is going to change. So you have to press proper link to see real result after changing language. I didnt accept that so i tried to do redirecting to Home page if u change the language.

    language-selector.tpl

    find -->
    <li{if $smarty.const.IA_LANGUAGE == $code} class="active"{/if}><a href="{ia_page_url code=$code}" title="{$language.title}">{$language.title}</a></li>

    replace---->

    <li{if $smarty.const.IA_LANGUAGE == $code} class="active"{/if}><a href="{ia_page_url code=$code destination='Home'}" title="{$language.title}">{$language.title}</a></li>


    ia.core.smarty.php

    ----> find

    public static function ia_page_url($params)
    {
    $isoCode = isset($params['code']) ? $params['code'] : '';
    $currentUrl = isset($params['url']) ? $params['url'] : IA_SELF;

    return IA_CLEAR_URL . $isoCode . IA_URL_DELIMITER . str_replace(IA_URL, '', $currentUrl);
    }


    ----> replace

    public static function ia_page_url($params)
    {
    $isoCode = isset($params['code']) ? $params['code'] : '';
    $currentUrl = isset($params['url']) ? $params['url'] : IA_SELF;
    $destinationX = isset($params['destination']) ? $params['destination'] : '';
    if($destinationX == "Home")
    return IA_CLEAR_URL . $isoCode . IA_URL_DELIMITER . str_replace(IA_URL, '', IA_URL);
    else
    return IA_CLEAR_URL . $isoCode . IA_URL_DELIMITER . str_replace(IA_URL, '', $currentUrl);
    }



    Thats all. As i said before for manytimes i am not php expert and i am kinda new but i like to solve problems. So this is my approach. Sorry for my bad grammar but i hope u understand it.
    Last edited: Oct 25, 2017
  2. Vasily_B.

    Vasily_B. Project Manager

    Hi

    Unfortunately there is no way to have different version of URLs for each language. URL is a unique identifier of page, and it's now only available in one primary language.
    It would be a custom modification if you want to change that as there is no easy solution.

    Thanks
  3. XCravenX

    XCravenX New Member

    So i cannot hide any specific menu for chosen language too?
  4. XCravenX

    XCravenX New Member

    Btw i ve done with it by myself but only little problem left. Can you tell me where is the language switch code location? Because i want to use $this->iaCore->util()->go_to(IA_URL); this code for forwarding to Home page when people switching language.
  5. XCravenX

    XCravenX New Member

    Okay i solved it. i ll replace solution for everyone who want to do multilanguage page url.
    Vasily_B. likes this.
  6. Vasily_B.

    Vasily_B. Project Manager

    Thanks for sharing your solution.

    It's language-selector.tpl file located in templates/_common/ folder. Just copy it to your real template folder and modify there.

    Cheers

Share This Page