Zend Framework

Zend_Translate_Adapter_Csv constant support

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Trivial Trivial
  • Resolution: Won't Fix
  • Affects Version/s: None
  • Fix Version/s: 1.10.0
  • Component/s: Zend_Translate
  • Labels:
    None

Description

Hello,

I use csv translate adapter and class constant keys like Zend_Validate_NotEmpty::IS_EMPTY are not supported.

I've made a trivial patch to solve this

— line 84 ----
$key = defined($data[0])?constant($data[0]): $data[0];

if (count($data) == 2) { $this->_data[$locale][$key] = $data[1]; } else { $singular = array_shift($data); $this->_data[$locale][$singular] = $data; }

Activity

Hide
Thomas Weidner added a comment -

Please give an example of what you want to archive.
Actually I just see problems with your change.

Related to Zend_Validate's translation there is already a resource file available which can be used.

Show
Thomas Weidner added a comment - Please give an example of what you want to archive. Actually I just see problems with your change. Related to Zend_Validate's translation there is already a resource file available which can be used.
Hide
Thomas Weidner added a comment -

Closing as incomplete as there is no response.

Show
Thomas Weidner added a comment - Closing as incomplete as there is no response.
Hide
Sébastien Cramatte added a comment - - edited

What I mean is if you use any other "Zend_Translate_Adapter_*" than "Zend_Translate_Adapter_Array" you can't use constant like Zend_Validate_NotEmpty::IS_EMPTY to make your Zend_Validate translation.

You must put the exact string as specified in the source class:
self::IS_EMPTY = "Value is required and can't be empty".

If for any reason somebody change this hardcoded string, form validation will not be translated properly.

I've got a project that must translated in 5 languages and it's fare easy to use constant in translation data (in my case I use CSV adapter).

Example (CSV file) :

...
Zend_Validate_NotEmpty::IS_EMPTY;Cette valeur ne peut être vide

Show
Sébastien Cramatte added a comment - - edited What I mean is if you use any other "Zend_Translate_Adapter_*" than "Zend_Translate_Adapter_Array" you can't use constant like Zend_Validate_NotEmpty::IS_EMPTY to make your Zend_Validate translation. You must put the exact string as specified in the source class: self::IS_EMPTY = "Value is required and can't be empty". If for any reason somebody change this hardcoded string, form validation will not be translated properly. I've got a project that must translated in 5 languages and it's fare easy to use constant in translation data (in my case I use CSV adapter). Example (CSV file) : ... Zend_Validate_NotEmpty::IS_EMPTY;Cette valeur ne peut être vide
Hide
Thomas Weidner added a comment -

This would not work as expected.
See the following example:

Expect this original:
Zend_Validate_File::EMPTY => 'file is empty'

Now you do:
"Zend_Validate_File::EMPTY";"file is empty"

Then there is a change in the constant

Zend_Validate_File::EMPTY => 'file or directory is empty'

But as you set the translation by constant it would for you still return
"file is empty".

This is not expected behaviour, it would even make more problems than getting an "no translation warning" which returns the original string.

Therefor it is always better to have
'file is empty'; 'translated text'
as it prevents you from further problems. You would have to do a new translation in any case. But by allowing constants you would not know that anything has changed.

And to prevent typing there are existing resource files which could be used.

Show
Thomas Weidner added a comment - This would not work as expected. See the following example: Expect this original: Zend_Validate_File::EMPTY => 'file is empty' Now you do: "Zend_Validate_File::EMPTY";"file is empty" Then there is a change in the constant Zend_Validate_File::EMPTY => 'file or directory is empty' But as you set the translation by constant it would for you still return "file is empty". This is not expected behaviour, it would even make more problems than getting an "no translation warning" which returns the original string. Therefor it is always better to have 'file is empty'; 'translated text' as it prevents you from further problems. You would have to do a new translation in any case. But by allowing constants you would not know that anything has changed. And to prevent typing there are existing resource files which could be used.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: