I am writing to php. Interesting is not the implementation, but the idea itself.
- onemuch depends on the principle of realization - Palmervan
- @myvzar, do not reward points for good answers, especially while you have few of them. Better click on "thumbs up" for good answers. And when you get comprehensive information, click on the checkbox next to the best answer. - Oleg Arkhipov
3 answers
For interface words, it is convenient to store in a file, as Opera, for example, and many others do. In the output you write something like:
<ul> <li><?= __('main') ?></li> <li><?= __('about') ?></li> </ul>
And the __ () method simply returns the value by the array key, which you can for example put ru.php in the file:
<?php return array( 'main' => 'Главная', 'about' => 'О нас', );
- In principle, this is a different implementation of the ini-file, but thanks for the idea of the function with the name
__
. Convenient (in the sense of not only for this). - Oleg Arkhipov - onethe idea is not mine. Thus, multilingualism is implemented in my favorite kohana framework (kohanaframework.org) - Vitaly Kustov
It’s probably easier to keep translated interfaces as a whole.
That is, separate directories of templates for different languages.
Palmervan is also a good decision. IMHO, it is suitable when the text is not very much, and it will be more convenient to mine.
And mine is better when there is a lot of it. It seems to me.
You determine the country by the client’s IP address and, on the basis of this data, you make a SELECT query to the part of the database which is written in the required language.
Added from comment.
All interface elements can be transferred to the base. If this is a picture, then store in the database links to it in different languages. If the button, then keep its label and so on. Then inside the PHP script, make a SELECT request. Overtake its result into local variables of the script and make an interface based on the values of these variables. Like that
$a = mysql_query("SELECT foo"); // Обработка a // Вывод элемента интерфейса echo "<div id =foo type = button caption =" + $a + "</div>";
- I did not mean it a little. Well, for example, for news, you can create different tables in the database. But parts of the interface? What's wrong with them? Where are they? save the interface in chunks (in different languages), or save only the words that need to be translated? - Mike
- Moved in response. - igumnov
- @igumnov, with pictures it is easier to do just separate directories (with names associated with the names of languages) and simply substitute to the address. - Oleg Arkhipov
- > by IP address Tin! There is also an Accept-Language header! - karmadro4