I have been using PHPixie for quite some time now and am very pleased, the only thing I lacked was support for multilingualism. Since I work in Kazakhstan, most customers want several localizations on their website, especially for government agencies. PHPixie was my first framework, I didn’t want to switch to something else (although I confess I almost changed it with an old woman, Kohana) and I wrote “ugly crutches” to implement multilingualism. In this article, we will discuss my new, quite convenient and elegant “crutch”, which I decided to share - the “PHPixie Amalgama” module."phpixie/amalgama": "2.*@dev" php composer.phar update -o --prefer-dist return array( // 'list' => array('en', 'ru', 'kk'), // 'default' => 'en', // , 'autorouting' => true, // , 'autoroutingExcept' => '^admin_' ); namespace App; class Pixie extends \PHPixie\Amalgama\Pixie { ... protected function after_bootstrap() { parent::after_bootstrap(); } } protected $modules = array( ... 'amalgama' => '\PHPixie\Amalgama' ); <?php namespace App; class Page extends \PHPixie\Amalgama\Controller { public function before() { parent::before(); ... } ... } 'default' => array( array('(/<lang>)(/<controller>(/<action>(/<id>)))', array('lang' => '(en|ru|kk)') array( 'controller' => 'hello', 'action' => 'index', 'lang' => 'en' ), ), //ru.php <?php return array( 'Hello World!' => ' !', 'Hello <?>!' => ' <?>!' ); //kk.php return array( 'Hello World!' => 'Cә ә!', 'Hello <?>!' => 'Cә <?>!' ); <?php echo $__('Hello World!'); // " !" ?> <?php echo $__('Hello <?>!', array('')); // " !" ?> <?php foreach($this->helper->getLangList() as $lang) : ?> <?php if ($lang == $this->helper->getCurrentLang()) : ?> <span><?php echo $lang; ?></span> <?php else: ?> <a href="<?php echo $this->helper->langSwitchLink($lang); ?>"><?php echo $lang; ?></a> <?php endif; ?> <?php endforeach; ?> $page = $this->request->param('page'); $comments = $this->pixie->orm->get('comment'); $pager = $this->pixie->paginate->orm($comments, $page, 10); $pager->set_url_route('comments', array('lang' => $this->lang)); $validator->field('username') ->rule('filled') ->error($this->__('Field <?> must not be empty', array($this->__('username')))); Source: https://habr.com/ru/post/244113/
All Articles