One fast way to do it would be to use an in-memory database.
Maybe first build your data files, exemple :
en_US.csv
hello_customer;Hello dear customer;
special_price;Special Price;
fr_FR.csv
hello_customer;Bonjour cher client;
special_price;Prix spécial;
...
Then install and configure redis
(key / value in memory database).
Get the extension (for instance for php : https://code.google.com/p/phpredis/)
Now build a script to populate your redis database. Maybe something along these lines:
<?php
$csv_path = 'path/to/csv/files';
function redis_import($f_name){
$handle = @fopen($f_name, "r");
$redis = new Redis();
$lang = explode('.', basename($f_name))[0];
if ($handle) {
$redis->connect('127.0.0.1', 6379);
while (($buffer = fgets($handle, 4096)) !== false) {
list($key, $value) = explode(';', trim($buffer));
$redis->set($lang.'.'.$key, $val);
}
if (!feof($handle)) {
echo "Erreur: fgets() a échoué\n";
}
fclose($handle);
}
}
if ($handle = opendir($csv_path)) {
while (false !== ($entry = readdir($handle))) {
if (!is_dir($entry)) {
redis_import($csv_path.PATH_SEPARATOR.$entry);
}
}
closedir($handle);
}
So whenever the csv files are modified, launch this script to populate the database.
Then you'll need a function in your script to fetch language data.
You could use sessions to store user language. Assuming you used $_SESSION['user.lang']
to do so, you could craft something like this :
function __translate($key){
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$translation = $redis->get($_SESSION['user.lang'] . $key);
$redis->close();
return $translation;
}
This solution is very fast there are just memory accesses, and still with the usage of csv files the real database is safe, and easily human accessible.