Is it possible to create a multilingual site only in php without mysql (database)
a good resource will be nice to have please provide
Is it possible to create a multilingual site only in php without mysql (database)
a good resource will be nice to have please provide
Yes, of course it is possible. gettext is the tried and tested way of doing that:
http://us2.php.net/manual/en/book.gettext.php
http://us2.php.net/manual/en/ref.gettext.php
Bear in mind, gettext is not thread-safe. If that bothers you there is a Zend Framework Component called Zend_Translate which has a gettext adapter which is thread-safe:
http://framework.zend.com/manual/en/zend.translate.adapter.html#zend.translate.adapter.gettext
Zend_Translate also has other adapters that do not rely on a database, such as:
Zend_Translate_Adapter_Array
(Store your text as native PHP arrays)Zend_Translate_Adapter_Csv
(Store your text as Comma-Separated Values)and many others.
I prefer more 'manual' way :-) Just include appropriate language file by analyzing cookie/session, and then use it on your template.
I have translations in XML file and they look like that:
English:
<?xml version="1.0"?>
<language>
<lang key="something">English 1</lang>
<lang key="something2">English 2</lang>
</language>
German:
<?xml version="1.0"?>
<language>
<lang key="something">Deutsch 1</lang>
<lang key="something2">Deutsch 2</lang>
</language>
So, the idea is keys in both files are the same, but node values are translated.
In PHP, I have special object which loads XML file (resolve language from session, url or whatever and load en.xml or de.xml file). In code, I use $Language->get('something2')
and text in right language is returned :)
The classical way is using arrays, spliced in separate files if they grow too big
<?php
$en = array(
'hello' => 'Hello World',
'username' => 'Your Username'
);
$fr = array(
'hello' => 'Bonjour Monde',
'username' => 'Votre Nom'
);
$current = ( $_GET['locale] === 'en')? $en : $fr;
echo $current['hello'];
?>
This is oversimplified, but the logic is correct.
I would also recomment Zend Translate, which implements all the backend solutions that I and the other users suggested in an OOP manner.