Open Sencillo  2015.107
Long live the simplicity of PHP
 All Data Structures Namespaces Functions Pages
translate.tool.framework.php
1 <?php
12 class translate extends fileSystem
13 {
14  protected $tSource;
15  protected $lang;
16 
17  public function __construct($name,$lang)
18  {
19  $this->name = $name;
20  $this->lang = $lang;
21 
22  if(file_exists($this->name))
23  {
24  $this->tSource = json_decode($this->read(),true);
25  }
26  }
27 
33  final public function translate($tKey)
34  {
35  return ($this->tSource[$tKey][$this->lang] ? $this->tSource[$tKey][$this->lang] : $tKey);
36  }
37 
45  final public function addTranslate($tKey,$tData)
46  {
47  if((is_string($tKey))&&(is_array($tData)))
48  {
49  $this->tSource[$tKey]=$tData;
50  $this->write(json_encode($this->tSource));
51  return true;
52  }
53  else
54  {
55  return false;
56  }
57  }
58 }
59 ?>