bushbaby / bsb-translate-controller-plugin
BsbTranslateControllerPlugin is a ZF2 module that provides controller plugin to expose the translator.
Installs: 2 459
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.3
- zendframework/zend-i18n: >=2.2.2
- zendframework/zend-modulemanager: >=2.2.2
- zendframework/zend-mvc: >=2.2.2
- zendframework/zend-servicemanager: >=2.2.2
This package is auto-updated.
Last update: 2020-03-23 18:30:53 UTC
README
BsbTranslateControllerPlugin is a small ZF2 module that registers a translator as controller plugin.
Installation
BsbTranslateControllerPlugin works with Composer. To install it into your project, just add the following line into your composer.json file:
"require": {
"bushbaby/bsb-translate-controller-plugin": "~1.0.0"
}
Then update your project by runnning composer.phar update.
Finally enable the module by adding BsbTranslateControllerPlugin in your application.config.php file.
Usage
Within an action controller you as plugins would use the translate and translatePlural view helpers.
Instead of using something ugly as;
$helper = $this->getServiceLocator()->get('viewhelpermanager')->get('translate');
echo $helper('message');
Use this;
echo $this->translate('message');
Instead of using something ugly as;
$helper = $this->getServiceLocator()->get('viewhelpermanager')->get('translateplural');
echo sprintf($helper('%s message', '%s messages', $number), $number);
Use this;
echo sprintf($this->translatePlural('%s message', '%s messages', $number), $number);