How to make the site multilingual?

I write in php. Interesting not implementation, but idea.


Answer 1, authority 100%

for interface buzzwords it is convenient to store in a file, as Opera does, for example, and a lot of others. 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 can be put in the ru.php file, for example:

<?php
return array(
  'main' => '',
  'about' => ' ',
);

Answer 2

It’s probably easier to save entire translated interfaces.
That is, separate directories of templates for different languages.
Palmervan has a good solution too. IMHO, it is suitable when there is not a lot of text, and it will be more convenient than mine.
And mine is better when there is a lot of it. I think so.


Answer 3

You determine the country by the IP address of the client and, based on this data, make a SELECT request to that part of the database that is written in the desired language.

Added from comment.

All interface elements can be transferred to the base. If this is a picture, then store links to it in different languages ​​in the database. If it’s a button, then keep its inscription, etc. Then, inside the PHP script, you make a SELECT query. Distill its result into local script variables and make an interface based on the values ​​of these variables. Something like this

$a = mysql_query("SELECT foo");
//  a
//   
echo "<div id =foo type = button caption =" + $a + "</div>";

Leave a reply

Please enter your comment!
Please enter your name here