Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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