Интернационализация

Тема в разделе "PHP программирование", создана пользователем nws, 25 мар 2008.

  1. Andrew Stephanoff

    Andrew Stephanoff Гость

    а что такое динамический текст?
     
  2. nws

    nws Гость

    Уже разобрался:

    Component:

    Код (Text):
    <?php
    class P28nComponent extends Object
    {
    var $components = array('Session', 'Cookie');

    function startup()
    {
    if (!$this->Session->check('Config.language')) {
    $this->change(($this->Cookie->read('lang') ? $this->Cookie->read('lang') :
    DEFAULT_LANGUAGE));
    }
    }

    function change($lang = null)
    {
    if (!empty($lang)) {
    $this->Session->write('Config.language', $lang);
    $this->Cookie->write('lang', $lang, null, '+350 day');
    }
    }
    }
    ?>
    p28n_controller:

    Код (Text):
    <?php
    class P28nController extends AppController
    {
    var $name = 'P28n';
    var $uses = null;
    var $components = array('P28n');

    function change($lang = null)
    {
    $this->P28n->change($lang);

    $this->redirect($this->referer(null, true));
    }

    function shuntRequest()
    {
    $this->P28n->change($this->params['lang']);

    $args = func_get_args();
    $this->redirect("/" . implode("/", $args));
    }
    }
    ?>
    Some controller:

    Код (Text):
    <?php

    class PostsController extends AppController
    {
    var $name = 'Posts';
    var $components = array('P28n', 'Cookie');
    var $paginate = array('limit' => 4, 'order' => array('Post.id' => 'DESC'));
    var $helpers = array('Html', 'Form');


    function archive($id = null)
    {

    $this->pageTitle = __('logo', true) . ' :: ' . __('nazvanie stranici', true);
    $this->set('lang', $this->Cookie->read('lang'));

    $this->Post->id = $id;
    $this->set('post', $this->Post->read());

    $data = $this->paginate('Post');
    $this->set(compact('data'));
    }

    }
    ?>
    View:

    Код (Text):
    <? foreach($data as $post):?>
    <table >
    <tr>
    <td>
    <?echo $html->link($post['Post'][$lang.'_title'],'/posts/view1/'.$post['Post']['id']);?>
    <br> <?php echo $post['Post']['created']; ?>
    </td>
    </tr>
    <tr>
    <td >
    <?echo $html->image('uploads/' . $post['Post']['image'], array('border' => 0, 'width'=>120));?>
    </td>
    <td>
    <?php echo $post['Post'][$lang.'_short'];?>
    <?php echo $html->link(__('Dalee', true), '/posts/view1/'.$post['Post']['id']);?>
    </td>
    </tr>
    </table>
    <?php endforeach; ?>
    <table>
    <tr>
    <td align="center">
    <?echo $paginator->Prev(__('<<Preced', true),null,null,array('class'=>'disabled'))?>
    |<?php echo $paginator->numbers();?>
    <?echo $paginator->next(__('Urmat>>',true),null,null,array('class'=>'disabled'))?>
    </td>
    </tr>
    </table>
     

Поделиться этой страницей