Last active
September 14, 2016 18:10
-
-
Save samsonasik/779e4f09d7c9723b01a0defd32683069 to your computer and use it in GitHub Desktop.
setup i18n in expressive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// data/translate/id/foo.php | |
return [ | |
'Congratulations!' => 'Selamat!' | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// src/App/Helper/I18nDelegatorFactory.php | |
namespace App\Helper; | |
use Zend\I18n\View\HelperConfig; | |
use Zend\ServiceManager\Factory\DelegatorFactoryInterface; | |
use Interop\Container\ContainerInterface; | |
class I18nDelegatorFactory implements DelegatorFactoryInterface | |
{ | |
public function __invoke( | |
ContainerInterface $container, | |
$name, | |
callable $callback, | |
array $options = null | |
) { | |
$helpers = $callback(); | |
$config = new HelperConfig(); | |
$config->configureServiceManager($helpers); | |
return $helpers; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// config/autoload/templates.global.php | |
return [ | |
'dependencies' => [ | |
'delegators' => [ | |
\Zend\View\HelperPluginManager::class => [ | |
\App\Helper\I18nDelegatorFactory::class, | |
], | |
], | |
// others config | |
], | |
// others config | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//config/autoload/translator.global.php | |
return [ | |
'dependencies' => (new \Zend\I18n\ConfigProvider())->getDependencyConfig(), | |
'translator' => [ | |
'locale' => 'id', | |
'translation_file_patterns' => [ | |
[ | |
'type' => 'phparray', | |
'base_dir' => 'data/translate', | |
'pattern' => '%s/foo.php' | |
], | |
], | |
], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php echo $this->translate('Congratulations!'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment