PHP Classes

File: translator.class.php

Recommend this page to a friend!
  Classes of Name Removed   PHP Translation Text From Files   translator.class.php   Download  
File: translator.class.php
Role: Class source
Content type: text/plain
Description: Class
Class: PHP Translation Text From Files
Translate application texts with translation files
Author: By
Last change: .
Date: 8 years ago
Size: 826 bytes
 

Contents

Class file image Download
<?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;
    }
}
?>