Версия для печати темы

Нажмите сюда для просмотра этой темы в обычном формате

Форум программистов _ PHP программирование _ Интернационализация

Автор: nws 25:03:2008, 13:37

Kак сделать интернализацию в cake_1.2.0.6311-beta для динамического текста?

Статьи, которые я нашел по этой теме:

]]>http://forum.codeby.net/go.php?http://cake-php.ru/wiki/Manual/Localization]]>
]]>http://forum.codeby.net/go.php?http://blog.difane.com/2007/09/10/multilanguage-site-part-1-static-text/]]>
]]>http://forum.codeby.net/go.php?http://bakery.cakephp.org/articles/view/p28n-the-top-to-bottom-persistent-internationalization-tutorial]]>

но в них описано только для статического текста ((

Автор: Andrew Stephanoff 4:05:2008, 20:20

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

Автор: nws 5:05:2008, 09:57

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

Component:

<?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:

<?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:

<?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:

<? 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>

Форум Invision Power Board (http://nulled.ws)
© Invision Power Services (http://nulled.ws)