phpixie/amalgama 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phpixie/amalgama

Composer 安装命令:

composer require phpixie/amalgama

包简介

PHPixie internationalization library

README 文档

README

  • Simple to use
  • No lang param in url for default language
  • Params in translations
  • Auto routes modify

Setup

  • Define this package in "require" section of composer.json
"phpixie/amalgama": "2.*@dev"
  • Update packages
php composer.phar update -o  --prefer-dist
  • Add a config file under /assets/config/amalgama.php
return array(
  // The list of languages
  'list' => array('en', 'ru', 'kk'),
  // Default language
  'default' => 'en',
  // For using autorouting extension
  'autorouting' => true,
  // Names of routes for except them from autorouting extension
  'autoroutingExcept' => '^admin_'
);
  • Override your Pixie.php
namespace App;

class Pixie extends \PHPixie\Amalgama\Pixie {
  ...
  protected function after_bootstrap() {
    parent::after_bootstrap();
  }
}
  • Define module in your Pixie.php
protected $modules = array(
  ...
  'amalgama' => '\PHPixie\Amalgama'
);
  • Override your base controller
<?php

namespace App;

class Page extends \PHPixie\Amalgama\Controller {

  public function before() {
    parent::before();
    ...
  }

  ...

}
  • Define routes(If you don't want use autorouting extension)
'default' => array(
  array('(/<lang>)(/<controller>(/<action>(/<id>)))', array('lang' => '(en|ru)')
  array(
    'controller' => 'hello',
    'action' => 'index',
    'lang' => 'en'
  ),
),
  • Add translation files under /assets/config/amalgama
//ru.php
<?php

return array(
  'Hello World!' => 'Привет мир!',
  'Hello <?>!' => 'Привет <?>!'
);

Usage

// view example
<div><?php $__('Hello World!'); ?></div>
<div><?php $__('Hello <?>!', array($user->name); ?></div>
// lang switcher example
<?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; ?>
// Paginate example
...
$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));
...
// Validate example
$validator->field('username')
  ->rule('filled')
  ->error($this->__('Field <?> must not be empty', array($this->__('username'))));

统计信息

  • 总下载量: 94
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2014-11-17