Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

I18n - Allow custom translation loaders to be injected via module config #6244 #6246

Conversation

rodmcnew
Copy link
Contributor

@rodmcnew rodmcnew commented May 8, 2014

This change allows modules to add their own translation loaders to the I18n translator via config like this:

'translator_loaders' => array(
    'factories' => array(
        'my_new_loader' => 'ZendI18nDoctrineLoader\Factory\LoaderFactory',
    )
),

Before there was no way to add translation loaders without defining your own new translator service. See the ticket for more details: #6244

namespace Zend\Mvc\Service;


class TranslatorLoaderManagerFactory extends AbstractPluginManagerFactory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make consistent, I think we should avoid wording "Loader" like ControllerLoader that will be replaced with ControllerManager in ZF3. see #4962

@rodmcnew
Copy link
Contributor Author

rodmcnew commented May 8, 2014

Samsonasik,

I agree that the word "loader" is confusing but I don't know what word would be a better substitute in this case. In ZF2 I18n, there is the FileLoaderInterface and RemoteLoaderInterface and this service manager is a container that contains only classes that are translation "Loaders".

public function validatePlugin($plugin)
    {
        if ($plugin instanceof Loader\FileLoaderInterface || $plugin instanceof Loader\RemoteLoaderInterface) {
            // we're okay
            return;
     }

The most important element of this PR is the config key that is being added. Currently I have it named "translator_loaders" and it is a place where you can specify your own translation loaders. Does anyone have an idea for a better name?

@rodmcnew
Copy link
Contributor Author

rodmcnew commented May 8, 2014

Perhaps changing the name to "translator_plugins" is more inline with the framework?

@samsonasik
Copy link
Contributor

I'm personally 👍 for 'translator_plugins'

@rodmcnew
Copy link
Contributor Author

rodmcnew commented May 8, 2014

I renamed the translation loaders to plugins:

'TranslatorPluginManager',
'translator_plugins',
'Zend\ModuleManager\Feature\TranslatorPluginProviderInterface',
'getTranslatorPluginConfig'

@Ocramius Ocramius added I18n and removed EventManager labels May 9, 2014

$translator = $this->factory->createService($serviceLocator);
$this->assertInstanceOf('Zend\Mvc\I18n\Translator', $translator);
$this->assertInstanceOf('Zend\I18n\Translator\Translator', $translator->getTranslator());

//#6244
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a new test and mark it as /** @group 6244 */ instead

@adamlundrigan
Copy link
Contributor

Is there a consensus on adding this? If so, @rodmcnew you'll need to add a blurb to the documentation about this feature to the appropriate page (PR to https://github.com/zendframework/zf2-documentation)

@rodmcnew
Copy link
Contributor Author

rodmcnew commented Dec 2, 2014

Sorry for the slow response. I wasn't getting mail notifications from Github so I didn't see the activity on this PR. I have updated this PR per everyone's requests. Please pull it or let me know if any other changes should be made. Thanks for the feedback everyone.

If this is pulled I will add a PR to add to the docs. I think this should be added to the "Configuration mapping table" table near the bottom of http://framework.zend.com/manual/2.2/en/tutorials/config.advanced.html

The Travis Build failed but it doesn't appear to be due to this PR so I'm not sure what I can do to fix that. It failed on "ZendTest\Cache\Storage\Adapter\FilesystemTest::testTouchItem"

@rodmcnew
Copy link
Contributor Author

rodmcnew commented Dec 2, 2014

The build passed

@@ -107,11 +150,14 @@ public function testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfa
//get any plugins with AbstractPluginManagerFactory
$routePluginManagerFactory = new RoutePluginManagerFactory;
$routePluginManager = $routePluginManagerFactory->createService($serviceLocator);
$this->assertInstanceOf(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How's this relevant for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my original PR I removed the unused var $routePluginManager leaving L152 as:
$routePluginManagerFactory->createService($serviceLocator);

@Ocramius suggested that we keep the var and assert on it.

After looking at this more, my personal opinion is that we are in the test for the TranslatorServiceFactory and should not be doing assertions against the RoutePluginManagerFactory's functionality.

If clean code is more important, I think the best thing to do is to remove this assertion and remove the unused $routePluginManager var. If PR relevance is more important, I could remove all changes to this test from this PR, leaving unused $routePluginManager var intact.

@rodmcnew
Copy link
Contributor Author

rodmcnew commented Dec 4, 2014

@DASPRiD I fixed your two concerns and the build is passing.

I fixed my added test so it is now properly testing the following line that is inside the TranslatorServiceFactory
$i18nTranslator->setPluginManager($serviceLocator->get('TranslatorPluginManager'));

I removed the changes to the unrelated test that you pointed out.

interface TranslatorPluginProviderInterface
{
/**
* Expected to return \Zend\ServiceManager\Config object or array to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundancy with documentation @return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the same doc block on this that is used in the rest of the framework for provider interfaces. Examples include the ControllerPluginProviderInterface and FilterProviderInterface among many others.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodmcnew Okay. Thanks for the explanation.

@rodmcnew
Copy link
Contributor Author

Closing and opening PR to trigger travis rebuild...

@rodmcnew rodmcnew closed this Jan 12, 2015
@rodmcnew rodmcnew reopened this Jan 12, 2015
@rodmcnew
Copy link
Contributor Author

The build failed in the following file which I don't believe has anything to do with this PR. Is there a way for me to trigger a Travis Rebuild?

/home/travis/build/zendframework/zf2/tests/ZendTest/Cache/Storage/Adapter/CommonAdapterTest.php:862

@Ocramius
Copy link
Member

@rodmcnew that's (sadly) a test that fails every time the I/O is very slow in the travis infrastructure.

@rodmcnew
Copy link
Contributor Author

I see, thanks @Ocramius.

@@ -59,6 +59,7 @@ class ServiceListenerFactory implements FactoryInterface
'InputFilterManager' => 'Zend\Mvc\Service\InputFilterManagerFactory',
'LogProcessorManager' => 'Zend\Mvc\Service\LogProcessorManagerFactory',
'LogWriterManager' => 'Zend\Mvc\Service\LogWriterManagerFactory',
'TranslatorPluginManager' => 'Zend\Mvc\Service\TranslatorPluginManagerFactory',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to keep these alphabetized; I can make that change on merge, however.

weierophinney added a commit that referenced this pull request Feb 19, 2015
…config

 I18n - Allow custom translation loaders to be injected via module config #6244

Conflicts:
	library/Zend/Mvc/Service/ServiceListenerFactory.php
weierophinney added a commit that referenced this pull request Feb 19, 2015
- Removed extraneous line
weierophinney added a commit that referenced this pull request Feb 19, 2015
@weierophinney
Copy link
Member

Merged for 2.4.0; @rodmcnew , please do a PR against https://github.com/zendframework/zf2-documentation with documentation of this feature. :)

weierophinney added a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
…4-translation-loaders-from-config

 I18n - Allow custom translation loaders to be injected via module config zendframework/zendframework#6244

Conflicts:
	library/Zend/Mvc/Service/ServiceListenerFactory.php
weierophinney added a commit to zendframework/zend-modulemanager that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants