Answer the question
In order to leave comments, you need to log in
What's the best way to do multiple languages?
I am writing a self-written engine of one site.
There is a task to make several languages on the site, but I don’t want to produce folders for us:
/ ru
/ en
/ pl
and put all the files into each folder again.
All data is taken from the database. Of course already created an array with phrases for each language. But the problem is that you need to make links according to the type as above, but not to produce heaps of folders.
How can this be done? Can you do something in htaccess by type, if there is a get parameter ?lang=ru then redirect to the same link just substitute the ru folder or if ?lang=en then redirect to the en folder?
Answer the question
In order to leave comments, you need to log in
Set the default language to Russian, create 'lang.php', where you take get lang. And depending on the language, output the word from the array.
Haven't posted in a while, but still:
if(isset($_SESSION['lang'])) { include('/langs/'.$_SESSION['lang'].'.php'); }
<a href="/lang.php?lang=en">En</a>
<a href="/lang.php?lang=pl">Pl</a>
<p><?= $lang['hello'] ?>, <?= $user->username ?></p>
if(isset($_GET['lang'])) {
$_SESSION['lang'] = $_GET['lang'];
}
I am writing a self-written engine of one site.
If you write the engine yourself. Why are you doing this in PHP?
There are many nice and convenient tools in the world.
Why choose something inferior.
--------
How would I do the localization.
I would define a global hashmap in a separate file. And a function that maps your standard localization to hashmap localization.
Fast, no parsing, no databases and other files.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question