How am I supposed to do anything in the url always have a language parameter?



  • Hello!
    I have a multilingualism, and my tongue goes to bed. lang = en
    When I pee in the urn site.ru/lang=ru I don't know. lang = ru and the site works in Russian!
    But then the parameter in the disappears!
    How am I supposed to do anything in the url always have a language parameter? site.ru/en/catalog.php or site.ru/ru/catalog.php etc.

    How do we get a multilingual routing?



  • We just need to get a library that can generate links for you.

    For example:

    https://github.com/mrjgreen/phroute#named-routes-for-reverse-routing

    <?php
        $router->get(['/{lang}/{name}', 'page_link'], function($lang, $name){
            return sprintf('Hello %s %s', $lang, $page);
        })
    

    And there'll be:

    <?php 
    
    $lang = $_COOKIE["lang"] ? $_COOKIE["lang"] : 'en';
    
    echo sprintf(
        "&lt;a href='%s'&gt;%s&lt;/a&gt;",
        $router-&gt;route('page_link', [$lang, 'about']),
        'about'
    );
    // prints &lt;a href='/en/about'&gt;about&lt;/a&gt;
    

    And also if you change the way.
    /{lang}/{name} - Category /static/{lang}/{name}

    You don't have to change your templates!

    Any library that can do that...

    Myself: https://www.google.ca/search?q=php+router+library




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2