zend-i18n
zend-i18n copied to clipboard
Using a Filesystem cache storage adapter results in an exception
Object of class Zend\I18n\Translator\TextDomain could not be converted to string
Switching to another adapter (like memory
) works fine, looks like this happens because Filesystem
doesn’t do any serialization, just:
// Zend\Cache\Storage\Adapter\Filesystem::putFileContent()
if (! is_string($data)) {
// Ensure we have a string
$data = (string) $data;
}
I’m not sure if Translator
should serialize the TextDomain
object before storing it, or if this is more a bug in the cache adapter. Perhaps we should check whether the cache can indeed store objects by using $cache->getCapabilities()
, and serialize it if not?
@kinglozzer
the following works for me:
try installing zend-serializer and this configuration (i use a global config file for i18n in order to have language files inside a /path/to/app/lang
dir, you can use a per-module config with getcwd()
call replaced by __DIR__
)
return [
//...
'translator' => [
//..
'cache' => [
'adapter' => [
'name' => 'filesystem',
'options' => [
'cache_dir' => getcwd() . '/data/cache',
'ttl' => 3600,
],
],
'plugins' => [
'serializer',
'exception_handler' => [
'throw_exceptions' => false,
],
],
],
];
kind regards, maks
This repository has been closed and moved to laminas/laminas-i18n; a new issue has been opened at https://github.com/laminas/laminas-i18n/issues/10.