<?php
class Translator extends EntityRepository {
    
   public function __construct() {
       
   }
   
   public function _getTranslation($key){
       $tools = new Tools();
       $keyOrigin = $key;
       $noTranlationOriginal = $tools->get_string_between($key,'{%','%}');

       $key = strtolower($key);
       $key = str_replace(" ", "", $key);
       $key = trim($key);

       $noTranlation = $tools->get_string_between($key,'{%','%}');          
       $key = str_replace($noTranlation, '', $key);
      
       if(isset($_SESSION['Wtranslator'][$key])){
           $traslation = $_SESSION['Wtranslator'][$key];
           //echo "<pre>";var_dump($traslation);echo "</pre>";
           $traslation = str_replace('{%%}', $noTranlationOriginal, $traslation);
           
           return $traslation;
       }else{
           return $keyOrigin;
       }
   }
   
   public function setLenguage(){
       $query = "SELECT id,_es FROM translator";
       $result = $this->query($query);
       
       if($result->num_rows > 0){
           $array = array();
          while($row = $result->fetch_object()){
              $array[$row->id] = $row->$lenguage;
          }
          
          $_SESSION['Wtranslator'] =  $array;
       }
       return array();
   }
}