ZF-11830: Dynamic locale changing in Zend_View_Helper_Translate can cause unexpected failures


The logic in Zend_View_Helper_Translate->translate() that allows changing the locale by passing it as the last parameter can cause normal-looking code to inexplicably fail. For example, take the following view code: bq. $this->translate('num %d name %s', $obj->id, $obj->name)

This will generate "vsprintf(): Too few arguments" errors if $obj->name happens to be a valid locale (e.g. "it"). Personally, I think this behavior should be removed since it violates the principle of least surprise, but that would be a BC-break. I think a good compromise would be to have Zend_View_Helper_Translate->translate() do some additional checking and not treat the last parameter as a locale if doing so would cause a "Too few arguments" error. Here's a patch that implements this:


You will need to sign and submit a CLA before we can apply your suggested improvement. See here:…

This patch was developed at -- Mason is another coder here, and I have signed the CLA (for the entire company). Can this patch be submitted under my CLA? Can you update Mason's user account to be covered by the same CLA? Thanks!

Andy Fowler

Added to ZF2 with GH-521.