-
Notifications
You must be signed in to change notification settings - Fork 2.5k
I18n - Allow custom translation loaders to be injected via module config #6244 #6246
I18n - Allow custom translation loaders to be injected via module config #6244 #6246
Conversation
namespace Zend\Mvc\Service; | ||
|
||
|
||
class TranslatorLoaderManagerFactory extends AbstractPluginManagerFactory |
There was a problem hiding this comment.
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
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? |
Perhaps changing the name to "translator_plugins" is more inline with the framework? |
I'm personally 👍 for 'translator_plugins' |
I renamed the translation loaders to plugins: 'TranslatorPluginManager', |
|
||
$translator = $this->factory->createService($serviceLocator); | ||
$this->assertInstanceOf('Zend\Mvc\I18n\Translator', $translator); | ||
$this->assertInstanceOf('Zend\I18n\Translator\Translator', $translator->getTranslator()); | ||
|
||
//#6244 |
There was a problem hiding this comment.
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
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) |
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" |
The build passed |
@@ -107,11 +150,14 @@ public function testReturnsTranslatorBasedOnConfigurationWhenNoTranslatorInterfa | |||
//get any plugins with AbstractPluginManagerFactory | |||
$routePluginManagerFactory = new RoutePluginManagerFactory; | |||
$routePluginManager = $routePluginManagerFactory->createService($serviceLocator); | |||
$this->assertInstanceOf( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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 I removed the changes to the unrelated test that you pointed out. |
interface TranslatorPluginProviderInterface | ||
{ | ||
/** | ||
* Expected to return \Zend\ServiceManager\Config object or array to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundancy with documentation @return
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Closing and opening PR to trigger travis rebuild... |
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 |
@rodmcnew that's (sadly) a test that fails every time the I/O is very slow in the travis infrastructure. |
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', |
There was a problem hiding this comment.
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.
…config I18n - Allow custom translation loaders to be injected via module config #6244 Conflicts: library/Zend/Mvc/Service/ServiceListenerFactory.php
- Removed extraneous line
Merged for 2.4.0; @rodmcnew , please do a PR against https://github.com/zendframework/zf2-documentation with documentation of this feature. :) |
…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
This change allows modules to add their own translation loaders to the I18n translator via config like this:
Before there was no way to add translation loaders without defining your own new translator service. See the ticket for more details: #6244