Interested in the question of which translation method is the best in functionality, speed, simplicity? But the main thing is to use your own scripts, without third-party plug-ins or resources.

My options are:
1. Through the file. (.txt)
2. Database.
3. Store all words in a PHP array.

I saw the option, depending on the country, the php code opens one or another .txt file, where there are actually 2 columns, on the left there are Russian words and on the right there is a translation into a certain language.
If this is the best way, I would appreciate the help in writing the script or links to the necessary information.
Thank.

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants of Grundy , aleksandr barakin , cheops , Bald , jfs 13 Sep '16 at 10:20 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • for me, better keep the translations in a php array, such as en.php, ru.php - Vfvtnjd

3 answers 3

<?php // Устанавливаем русский язык putenv('LC_ALL=ru_RU'); setlocale(LC_ALL, 'ru_RU'); // Указываем путь к таблицам переводов bindtextdomain("myPHPApp", "./locale"); // Выбираем домен textdomain("myPHPApp"); // Теперь поиск переводов будет идти в ./locale/ru_RU/LC_MESSAGES/myPHPApp.mo // Выводим тестовое сообщение echo gettext("Welcome to My PHP Application"); // Или с использованием псевдонима _() echo _("Have a nice day"); ?> 

More details here: http://php.net/manual/ru/function.gettext.php

    "no third-party plug-ins or resources." very difficult task. What I can offer from the fastest methods, create a ney class of languages ​​and with the help of its functions get a certain text (and edit the language in the class itself). "I saw the option, depending on the country" just parse the header ( $_SERVER["HTTP_ACCEPT_LANGUAGE"] , as an example http://tradebenefit.ru/kak-opredelit-jazyk-polzovatelja-v-php ) and get the language from it (select language, too, by the way).

    You can try the easy way to use Google translator https://translate.google.com/manager/website/ (I often see it on English sites).

    • A useful thing. But this is only the definition of the user's preferred language. I still need more the principle of translation itself, that is, for example, outputting a certain .txt file and inserting words on a site page. Or better through the database? - Albert Ushakov

    Found such a solution.

      //вырезаем первые две буквы $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); //Выводим значение языковой константы $array = parse_ini_file('leng/'.$lang.'.ini'); echo $array["hello"]; 

    In the file ru.ini I save the translation in the form:
    hello = hello

    • With each request to parse the same ini file - it is very, very sad. - Dmitriy Simushev
    • Well, you can save in the session, if this is possible. But otherwise I xs. - Albert Ushakov
    • Sessions are not intended to store significant amounts of data. - Dmitriy Simushev
    • Then it is easier to load the file. - Albert Ushakov
    • one
      Well, how would I have stuck this option, and I like it. There are not any lags. - Albert Ushakov