Services Defined

zend-mvc-i18n defines the following services and related factories.

Translator

Zend\Mvc\I18n\Translator implements each of Zend\I18n\Translator\TranslatorInterface (from zend-i18n) and implements Zend\Validator\TranslatorInterface (from zend-validator), by decorating an Zend\I18n\Translator\TranslatorInterface instance (typically a Zend\I18n\Translator\Translator instance).

It exists to allow bridging multiple translation interfaces, allowing it to be used in multiple contexts.

DummyTranslator

Zend\Mvc\I18n\DummyTranslator is an implementation of Zend\I18n\Translator\TranslatorInterface that essentially returns the arguments provided to it unchanged.

As an example, calling:

$translator->translate($message);

will return $message, and

$translator->translatePlural($singular, $plural, $number);

will return $singular when $number is 1, and $plural otherwise.

MvcTranslator and TranslatorFactory

The component defines the MvcTranslator service, which is aliased to the Zend\Mvc\I18n\Translator class, and uses Zend\Mvc\I18n\TranslatorFactory to create and return the instance.

The point of the service is to ensure that a Zend\Mvc\I18n\Translator instance is returned, which enables usage across multiple contexts (see the Translator section, above).

As such, you should typically use the MvcTranslator service when injecting your own classes with a translator instance:

function ($container) {
    return new YourServiceClass($container->get('MvcTranslator'));
}

The TranslatorFactory will do the following:

HttpRouterDelegatorFactory

The component registers a delegator factory on each of the HttpRouter and Zend\Router\Http\TreeRouteStack services. The delegator factory checks to see if the instance created is a Zend\Mvc\I18n\Router\TranslatorAwareTreeRouteStack, and, if so: