Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@samsonasik
Last active September 14, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsonasik/779e4f09d7c9723b01a0defd32683069 to your computer and use it in GitHub Desktop.
Save samsonasik/779e4f09d7c9723b01a0defd32683069 to your computer and use it in GitHub Desktop.
setup i18n in expressive
<?php
// data/translate/id/foo.php
return [
'Congratulations!' => 'Selamat!'
];
<?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;
}
}
<?php
// config/autoload/templates.global.php
return [
'dependencies' => [
'delegators' => [
\Zend\View\HelperPluginManager::class => [
\App\Helper\I18nDelegatorFactory::class,
],
],
// others config
],
// others config
];
<?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'
],
],
],
];
<?php echo $this->translate('Congratulations!'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment