That's what I googled. Saw such options is site.com/en or site.com/ru ie I chose a language, for example Russian, and if I go to the page about us, it will be something like that site.com/ru/o_nas, if in English then site.com/en/o_nas There is a page en and ru and through them it works. I also saw such index.php? Lang-en or index.php? Lang-ru, these get parameters are appended when I click on the language selection and let's say the main one has been translated, although I haven’t succeeded yet. but if you go to site.com/o_nas then these get parameters disappear. I need that when I clicked on en | ru, respectively, the site was completely transferred and which page I wouldn’t go to in the selected language. At the expense of cookies and sessions, they are not important now, the main thing is that until the browser is closed the language remains selected until the user switches to another.

OOP and the like is not necessary, the simplest on procedural.

I have everything taken from the database as I understand it. If you need 2 languages, then you need to create 2 o_nas_ru and o_nas_en tables each and then write to the right one. But in practice it does not work.

block to switch the language.

<div class="tag">Language:<a href="index.php?lang-en">English</a>|<a href="index.php?lang=ru">Русский</div> 

How to do what I described above, and that the necessary text from the admin panel was written to the desired table (there will be two fields in the admin panel at once, for example, for Russian and English. Text and in the database are different tables) and displayed depending on what is selected on the site ru or en? Can a small example to understand the essence.

And how to make a Russian standard, i.e. what would not just be index.php loaded into index.php.ru or index.php? lang.ru as correct?

    1 answer 1

    Let's imagine that the language on the site is switched using the GET variable lang. Then somewhere in the beginning of the script you need to check the choice of language:

     $lang = 'ru'; // Язык по умолчанию $available_lang = ['ru', 'en']; if (isset($_GET['lang']) AND in_array($_GET['lang'], $available_lang, true)) { $lang = $_GET['lang']; } 

    Now the $ lang prefix can be substituted for generating page names for the download ($ name_page = 'o_nas _'. $ Lang;). You should also add a language prefix to each link in order not to lose the user's choice.

    I advise you also to pay attention to the "single entry point" - see Google for details. In this case, all requests to the site can be processed in a single script.

    PS For those who like to make changes to the answer without checking: the line $ available_lang = {'ru', 'en'}; - incorrect PHP code, array can be initialized either like this: $ available_lang = ['ru', 'en']; either like this: $ available_lang = array ('ru', 'en'); Please do not make wrong changes to my answer. User Deonis in the comments to the answer posted a link to the documentation on PHP: http://php.net/manual/ru/language.types.array.php#example-99 where you can see how the arrays are initialized in PHP.

    • Thanks, I will try. And what are the other multi-language options besides get parameters? - Arthur Chereshnyuk 5:56
    • The parser says that the syntax error in this line is $ available_lang = ['ru', 'en']; - Arthur Chereshnyuk
    • @ArturChereshnyuk parser is silent that you have an old version of PHP ( not higher than 5.4 ) and does not support this array declaration syntax . - Deonis
    • Replace the string with $ available_lang = array ('ru', 'en'); Although, it is better not to use ancient PHP, and upgrade to the newest current version 5.6, and better 7.0 - Miron
    • You can think of many more ways to make a multilanguage site, except with the help of GET / URL, but note that in this case the search engines may reject / poorly index the site. - Miron