Translation Adapter

Good afternoon! I'm trying to create basic multi-lingual project. I'm using Phalcon\Translate\Adapter\NativeArray:

  $di->set('translate', function(){
      // Some Code

      return new \Phalcon\Translate\Adapter\NativeArray(array(
      "content" => $messages
      ));
  });

How can I access to multi-dimensional array? E.g: my en.php file:

  <?php

  $messages = [
          'pages' => ['index' => ['title' => 'Main',
                                             'greetings' => 'Hello %name%'
                                             ]
                            ]
           ];

In my controller:

    echo $this->translate['pages']['index']['title']; 

It will display the word "Main", but how can I replace %name% ? I need to use:

$this->translate->query(); 

But I don't know how to specify the index of multi-dimensional array as argument.

Thanks for your help.

I thnik there is some way to solve your problem but I never saw using multi-dimension array as translation resource.

I think its better to use multiple files instead of using multi-dimension array. a basic example is:

 $di->set('translate', function(){
      // Some Code
    $a = include '/path/tranlsation/en/pages.php';
    $b = include '/path/tranlsation/en/Users.php';
    $c = include '/path/tranlsation/en/Panel.php';
    $messages = array_merge($a, $b, $c);

    // Or include all files in /en/ path Or....

    // CACHE the array in memory (redis/memcache/...) for next usage

      return new \Phalcon\Translate\Adapter\NativeArray(array(
         "content" => $messages
      ));
  });

Thanks for your reply!



31.2k

Hi,

also, phalcon's incubator (https://github.com/phalcon/incubator) has some nice features regarding translations ...