A Zend Framework 2 Module for Google Translate
-
This module is available on Packagist. In your project's
composer.json
use:{ "require": { "php": ">=5.3.3", "zendframework/zendframework": "*", "gowsram/g-translate": "dev-master" }
-
Or clone this project into your
./vendor/
directory.
-
Enabling this module in your
application.config.php
file.return array( 'modules' => array( // ... 'GTranslate', // ... ), // ... );
-
In the controller
$gtranslate = $this->getServiceLocator()->get('GTranslate\Service\Translate'); $config = array( 'from' => 'en', //english 'to' => 'de', //deutsch ); $gtranslate->__initialize($config); $resultString = $gtranslate->translate('Hello World'); return new ViewModel(array('translatedString' => $resultString)); //passing it to the view
-
In the View
<?php echo $this->translatedString; ?>