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

ZF 2.3.0 BC break in MvcTranslator #5978

Closed
Martin-P opened this issue Mar 15, 2014 · 14 comments
Closed

ZF 2.3.0 BC break in MvcTranslator #5978

Martin-P opened this issue Mar 15, 2014 · 14 comments
Assignees
Milestone

Comments

@Martin-P
Copy link
Contributor

Commit 9be9748 was done with the message Ensure TranslatorServiceFactory remains BC with < 2.3.0. Unfortunately it does the opposite and introduces a BC break. It requires the intl extension to be active, without the intl extension I now can not use the translator.

TranslatorServiceFactory, line 37:

// If ext/intl is not loaded, return a dummy translator
if (!extension_loaded('intl')) {
    return new MvcTranslator(new DummyTranslator());
}

When I comment out the check for intl everything works perfectly as it did before, so this check is definately the cause of the problem.

This is the config I use for my translations:

'service_manager' => array(
    'aliases' => array(
        'translator' => 'MvcTranslator',
    ),
),

'translator' => array(
    'locale' => 'nl_NL',
    'translation_file_patterns' => array(
        array(
            'type'     => 'phparray',
            'base_dir' => __DIR__ . '/../language',
            'pattern'  => 'lang.array.%s.php',
        ),
    ),
),

Suggested fix:
Do not require the intl extension for using the translator.

@macnibblet
Copy link
Contributor

The intl extension is and has always been a requirement for ZendFramework if i'm not totally wrong.

@Martin-P
Copy link
Contributor Author

Sorry, but you're wrong :) I use translations since ZF 2.2.4 at least and my hosting company does not have the intl extension enabled. Online I still use ZF 2.2.6 and messages get translated perfectly without the intl extension.

I just updated on my local computer from ZF 2.2.6 to ZF 2.3.0 and during testing I noticed my text not being translated anymore. As you can see in the commit I referenced in my post, the check for intl was added in ZF 2.3.0 (#5942).

@pauloelr
Copy link
Contributor

AFAIK too "The intl extension is and has always been a requirement for ZendFramework" Quoting @macnibblet

@Martin-P
Copy link
Contributor Author

@pauloelr Same as I said to @macnibblet: look at the commit :) Or better: test it yourself with ZF 2.2.6 without intl and you will see the translator can be used without the intl extension in ZF 2.2.6 and earlier versions. I understand you both assume the intl extension to be required, but my report is not based on assumptions, but on facts ;) Fact is: it worked perfectly in ZF 2.2.6 and does not work in ZF 2.3.0.

Edit:
For those interested in a workaround:

  • Copy the file Zend\Mvc\Service\TranslatorServiceFactory to your own location, for instance Application\Mvc\Service\TranslatorServiceFactory
  • Comment out lines 38 - 40 in your newly created file
    Move lines 38 - 40 to just before the return statement in your newly created file
  • Add the following config which ensures your custom translator factory is used:
'service_manager' => array(
    'factories' => array(
        'MvcTranslator' => 'Application\Mvc\Service\TranslatorServiceFactory',
    ),
),

@DASPRiD
Copy link
Member

DASPRiD commented Mar 15, 2014

It's correct that, as long as a locale is configured, the Intl extension is not required by the translator.

@Martin-P
Copy link
Contributor Author

@DASPRiD I have a locale configured under the translator config key, but still get a DummyTranslator. If I look at Zend\Mvc\Service\TranslatorServiceFactory I don't see the check for locale you refer to. If I look at the previous version of Zend\Mvc\Service\TranslatorServiceFactory I don't see that check either. Am I doing something wrong? My workaround (see above) by removing the check for intl extension fixes everything, so I think I can say the check for the intl extension is causing the problem.

@DASPRiD
Copy link
Member

DASPRiD commented Mar 15, 2014

Right, but removing the check does not solve the problem. The actual problem is the order of all the checks. If I see it correct, the extension check should come just before the last return statement.

@Martin-P
Copy link
Contributor Author

I tested your suggestion and can confirm moving the check for intl fixes the problem.

@macnibblet
Copy link
Contributor

@Martin-P Create a pull request for it then

@Martin-P
Copy link
Contributor Author

Already working on it :)

@macnibblet
Copy link
Contributor

👍

@Ocramius Ocramius added bug and removed I18n labels Apr 3, 2014
@Ocramius Ocramius added this to the 2.3.1 milestone Apr 3, 2014
@Ocramius Ocramius self-assigned this Apr 3, 2014
Ocramius added a commit that referenced this issue Apr 3, 2014
@samsonasik
Copy link
Contributor

@Ocramius based on #5979 this issue can be closed now ?

@Ocramius
Copy link
Member

Ocramius commented Apr 5, 2014

@samsonasik thanks for the reminder :-)

@Ocramius Ocramius closed this as completed Apr 5, 2014
@samsonasik
Copy link
Contributor

@Ocramius you're welcome ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants