There is a duplicate English version of the site. The site is written in php. The Russian version is in the root, the English version is in the / en folder. The language used in the cookie is stored. I want to write a script that would automatically pull up the desired php file of the English or Russian version depending on this cookie. Cook changes js when you click a switch. And I would also like that when referring to the main page of the English version, the url was just

site.com/en/

Now when accessing this url, the site redirects to the main page at the root (ie the Russian version), now the main page of the English version can only be accessed

site.com/en/index

  • and what are the functional and technical requirements? - Vyacheslav Danshin

3 answers 3

Many frameworks have localization support. In the naive version, you can make a structure that stores the translation of each phrase in each language.

$messages["ru"]["msg.button"] = "Кнопка"; ... $messages["en"]["msg.button"] = "Button"; ... 

Getting the language can be done through the parameter:

 $lang = $_GET["lang"]; 

Then the output of the phrase will be:

 <button><?php echo $messages[$lang]["msg.button"]; ?></button> 

    The fastest way = Create 2 folders (for 2 languages)

    1 - /en
    2 - /ru

    You translate the site into 2 languages, and paste each into the correct folder with the language. You make a badge with links to different versions of the language

     <a href="/en/" hreflang="en"> <a href="/ru/" hreflang="ru"> 

    It turns out 2 copies of the site, with 2 different languages.

      Everything is very, very simple in fact. You create files with the identifier of the desired language, which contains arrays with phrase translations. Approximately, like this: File "ru.lang": $ lang = array (

      'save' => 'Save', 'true' => 'True'

      /* Etc. * /

      );

      File "en.lang": $ lang = array (

      'save' => 'Save', 'true' => 'True'

      / * etc * /

      );

      Then you create a script that, when received, for example, $ _GET ['lang'] checked the lang file and if it exists, then recorded (setcookie ('language', $ _GET ['lang', ...)) session with the necessary identifier.

      I am writing on my knee, but this is really all easy to implement. Do not forget only the language cuckoo to check for availability. If there is, then connect the desired file with the desired identifier.