Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I want to translate my ini files.
- I'm using a custom I18n\Translator\Loader\PhpIni class but i need to instanciate this class with a parameter "Site" into its constructor to get the correct 'section' of ini file.
- Here is my config file:
- 'translator' => array(
- 'locale' => 'fr_FR',
- 'translation_patterns' => array(
- array(
- 'type' => 'Mix\I18n\Translator\Loader\PhpIni',
- 'base_dir' => __DIR__ . '/../language',
- 'pattern' => 'common-%s.ini',
- 'text_domain' => 'application'
- )
- ),
- ),
- 'service_manager' => array(
- 'factories' => array(
- 'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
- 'Mix\I18n\Translator\Loader\PhpIni' => function ($serviceManager) {
- $site = $serviceManager->get('Mix\Site');
- $service = new Mix\I18n\Translator\Loader\PhpIni($site);
- return $service;
- },
- ),
- ),
- But i got the following error :
- Catchable fatal error: Argument 1 passed to Mix\I18n\Translator\Loader\PhpIni::__construct()
- must be an instance of Mix\Site, none given, called in vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php on line 177
- and defined in library\Mix\I18n\Translator\Loader\PhpIni.php on line 13
- Here is my PhpIni class:
- class PhpIni implements LoaderInterface
- {
- private $domain;
- public function __construct(\Mix\Site $site) {
- $this->domain = $site;
- }
- /**
- * load(): defined by LoaderInterface.
- *
- * @see LoaderInterface::load()
- * @param string $filename
- * @param string $locale
- * @return TextDomain|null
- * @throws Exception\InvalidArgumentException
- */
- public function load($filename, $locale) {
- $domainConfig = new \Mix\Config\Ini($filename, strtolower($this->domain->get('name')),false);
- if (!is_file($filename) || !is_readable($filename)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Could not open file %s for reading',
- $filename
- ));
- }
- if(count($domainConfig->toArray())>0) {
- $messages = $domainConfig->toArray();
- if (!is_array($messages)) {
- throw new Exception\InvalidArgumentException(sprintf(
- 'Expected an array, but received %s',
- gettype($messages)
- ));
- }
- $textDomain = new TextDomain($messages);
- if (array_key_exists('', $textDomain)) {
- if (isset($textDomain['']['plural_forms'])) {
- $textDomain->setPluralRule(
- PluralRule::fromString($textDomain['']['plural_forms'])
- );
- }
- unset($textDomain['']);
- }
- return $textDomain;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement