-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Fix BC break with skeleton for Translator Service #5689
Fix BC break with skeleton for Translator Service #5689
Conversation
- Mvc\TranslatorServiceFactory was missing the "implements FactoryInterface" declaration, making it fail as a valid factory. - Circular dependency was occurring, as changes in TranslatorServiceFactory meant it was looking for existence of an alias already defined in the skeleton, and pointing back at the same service. Added a 'Zend\I18n\Translator\TranslatorInterface' service, pointing to the I18n TranslatorServiceFactory, and now check for that in the MVC TranslatorServiceFactory. This fixes the primary BC issue. - Updated View\HelperPluginManager to look for (and conditionally fetch) the new 'Zend\I18n\Translator\TranslatorInterface' service, instead of the 'translator' service. This will preserve the intent. Developers may alias 'translator' to 'Zend\I18n\Translator\TranslatorInterface' if desired.
- Point of original PR that broke BC was to remove the requirement of ext-intl by default. Adding the TranslatorInterface as a service by default breaks this. Removed, and we can now document it.
- Covers zendframework#5406, and the changes also present in this PR.
- Check for each of MvcTranslator, Translator, and TranslatorInterface in order to perform injections. - Since "Translator" is usually an alias of "MvcTranslator", check this last.
- If no `TranslatorInterface` service is found, check for "translator" configuration, and use it to create a `Zend\I18n\Translator\Translator` instance, per original behavior. - **Always** wrap a created translator instance in a `Zend\Mvc\I18n\Translator` instance.
- No longer needed, as the MVC translator service factory now wraps a given translator in an Mvc\I18n\Translator instance. - Also, CS fixes
Okay, ready to merge now! |
I preferred the behavious of DASPRID PR ( #5406 ) Before his PR : I have like 10+ modules, with translation files for each one. array(
'translator' => array(
'translation_file_patterns' => array(
array(
'text_domain' => 'ice-admin-auth',
'type' => 'phparray',
'base_dir' => dirname(__DIR__) . '/i18n',
'pattern' => '%s.php'
)
)
)
) Translation files were loaded even if I didn't use translator. With his PR : None of my translation files are loaded if I didn't define 'translator' in the service manager. Now with this PR, all my translation file are loaded, or I have to remove 'translator' entry in each module config. |
The new Zend\Mvc\I18n\Translator (MvcTranslator) is lacking some public methods of the old Zend\I18n\Translator\Translator which it previously extended. The MvcTranslator also does not allow access to the protected $translator which makes it impossible now to change the locale on the fly for example. Will the MvcTranslator be extended before 2.3 goes to master, or we have to extend it in the future, so we can use those public functions? |
I had to account for this minor BC break in my custom Translator extension when updating from ZF 2.2.5 to 2.3.0. I now extend my custom Translator from namespace MyLib\I18n\Translator;
use Zend\Validator\Translator\TranslatorInterface as ValidatorTranslatorInterface;
class Translator extends \Zend\I18n\Translator\Translator implements ValidatorTranslatorInterface
{
// ...
} |
What I did was:
Zend\I18n\Translator\TranslatorInterface
service in the factory; if it exists, it is pulled and pushed into aZend\Mvc\I18n\Translator
instance, and that instance is returned.translator
key is present in configuration, and non-empty, that is passed toZend\I18n\Translator\Translator::factory
, and the result passed to aZend\Mvc\I18n\Translator
instance, which is returned.DummyTranslator
instance is created, passed to aZend\Mvc\I18n\Translator
instance, and that instance is returned.This addresses all BC breaks with the existing skeleton.
Fixes #5684 .