ZF-2256: Possibility to give a string as the source files in the array adapter Zend_Translate_Adapter_Array

Description

It can easily implement by adding 3 lines of code in Zend_Translate_Adapter_Array::_loadTranslationData()



if(!is_array($data)){
    $data = include($data); 
}

Then the array file should look like :


<?php
return array(
    'user_id'  => 'Id',
    'username' => 'Non utilisateur',
    'password' => 'Mot de passe',
    'email'    => 'Email',
    'firstname'=> 'Prénom',
    'lastname' => 'Nom',
    'created'  => 'Crée le',
    'modified' => 'Modifié le'
);

Comments

Why should an Array Adapter accept Strings ?

As per definition of the class name the usage is for "Arrays"... You can simply extend any existing adapter or write your own.

But I don't think that a "string" Adapter is usefull, because you could simply do


$t->addTranslation(array($key => $value));

Well, if you can do both its even better don't you think? :) There are a lot of classes in the frameworks were the argument is an object or a string, and in the later it will use a factory to get the object. So it could be done with array too.

But best, if you can provide a string the array adapter will work with the automatic source detection. My $0.2

It's not just that 3 lines. We have also to handle output and failures from the file.

Anyway, it has been integrated with SVN-7050.

Thanks Thomas ! :)

{quote} It's not just that 3 lines We have also to handle output and failures from the file. {quote}

That's right.

I think there is a more appropriated test


if(is_string($data)) 

Instead of the one I first suggested


if(!is_array($data))