<?php
// Translation From Files Class
// Developed by Takis Maletsas
// @2016
class Translator
{
private $language, $translations_dir = 'translations';
public function translate($string)
{
$path = realpath($this->translations_dir . '/' . $this->language . '.lang');
if (file_exists($path)) {
foreach (file($path) as $line)
$lines[] = explode('<=>', trim($line));
foreach ($lines as $value)
$lang[$value[0]] = $value[1];
} //endif
echo array_key_exists($string, $lang) ? $lang[$string] : $string;
}
public function set_language($language)
{
$this->language = $language;
}
public function set_translations_dir($dir)
{
$this->translations_dir = $dir;
}
}
?>
|