0

I'm pretty new to ZF and have a question regarding translator configuration. I have an application with the following translator configuration inside the module.cofig file:

'translator'         => [
    'locale' => 'ru_RU',
    'translation_file_patterns' => [
        [
            'type' => 'gettext',
            'base_dir' => __DIR__ . '/../language',
            'pattern' => '%s.mo',
        ],
        [
            'type' => 'phparray',
            'base_dir' => __DIR__ . '/../language',
            'pattern' => '%s.php',
        ],
    ],
    'cache' => \Zend\Cache\StorageFactory::factory(
        [
        'adapter' => [
            'name'    => 'Filesystem',
            'options' => [
                'cache_dir' => APPLICATION_LOAD_PATH . '/data/cache',
                'ttl'       => '3600',
            ],
        ],
        'plugins' => [
            [
                'name'    => 'serializer',
                'options' => [],
            ],
            'exception_handler' => [
                'throw_exceptions' => true,
            ],
        ],
        ]
    ),
],

This configuration works fine, but I want to know if is it possible to move this code inside Module.php trough the getTranslatorPluginConfig() . What I've tried is to use this method and return this same config:

public function getTranslatorPluginConfig(){
    return [
        'translator'         => [
            'locale' => 'ru_RU',
            'translation_file_patterns' => [
                [
                    'type' => 'gettext',
                    'base_dir' => __DIR__ . '/language',
                    'pattern' => '%s.mo',
                ],
                [
                    'type' => 'phparray',
                    'base_dir' => __DIR__ . '/language',
                    'pattern' => '%s.php',
                ],
            ],
            'cache' => \Zend\Cache\StorageFactory::factory(
                [
                    'adapter' => [
                        'name'    => Filesystem::class,
                        'options' => [
                            'cache_dir' => APPLICATION_LOAD_PATH . '/data/cache',
                            'ttl'       => '3600',
                        ],
                    ],
                    'plugins' => [
                        [
                            'name'    => 'serializer',
                            'options' => [],
                        ],
                        'exception_handler' => [
                            'throw_exceptions' => true,
                        ],
                    ],
                ]
            ),
        ],
    ];
}

As you can see I haven't changed anything (except base_dir path). I don't get any errors, but the translator is not working at all. If you can tell me what are the steps I need to take to make this configuration work from the Module file and if this is possible at all, I'll be grateful. I don't expect plain code, but just a guidance/suggestion of what could be done, since all I find in the Zend documentation is related with making this configuration inside module.config. Thanks in advance.

Angel Deykov
  • 1,199
  • 1
  • 9
  • 15
  • On a personal note, I think it would be better to keep this in configuration files in array format - these may be cached, increasing performance. On the other hand, you most likely have to remove the `translator` key (level) from the array the function returns. If you look at other configuration functions in `Module.php` examples, you'll see they do not have their "root" config key present, e.g. `getServiceManagerConfig` has only `factories`, `aliases`, etc. and not `service_manager`. – rkeet Dec 02 '18 at 15:37
  • sorry for the late reply, I've tried this removing the 'translator' key, but no result. I'm trying to move this to the Module, because my goal is to enable the 'config_cache_enabled' in my application.config.php. When I set this confin_cache to true it result to an error, 'Call to undefined method FileSystem::__set_state() ....' – Angel Deykov Dec 07 '18 at 07:02
  • This is related with the translator and moving the configuration to Module.php removes the error, but then the translator is not working. I'm still fighting this issue and if I find a way around I'll post it here – Angel Deykov Dec 07 '18 at 07:05

0 Answers0