Ecco la classe completa se interessa a qualcuno:
Codice PHP:
class Internalization {
public $debug = true;
private $array = array();
public function addPhrase($key, $value)
{
if($this->debug) {
$this->elementExist($value);
$this->keyExist($key);
}
$this->array[$key] = $value;
}
public function generateTranslation()
{
return $this->array;
}
private function elementExist($element)
{
if(in_array($element,$this->array)) {
throw new Exception($element.' Element already used.');
}
}
private function keyExist($key)
{
if(array_key_exists($key, $this->array)) {
throw new Exception($key.' Key already used.');
}
}
}
Ho aggiunto la variabile debug così da evitare i controlli nel momento in cui la traduzione è finita e aggiunto il controllo anche sul valore. Spero sia utile a chi si trova nel mio stesso caso!