Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Zend Framework] Zend_Translate
Skyline
post
Post #1





Grupa: Zarejestrowani
Postów: 63
Pomógł: 0
Dołączył: 25.07.2007

Ostrzeżenie: (0%)
-----


Witam

Czy można w jakiś sposob "globalnie" zadeklarowac i dodać słowniki, tak żeby nie tworzyć obiektu każdorazowo w każdym kontrolerze?

Mam taki kod i nie chcialbym go wlepiac w kazdy controller:

  1. <?php
  2. $translate = new Zend_Translate('array', ROOT_DIR . '/modules/default/languages/polish.php', 'pl');
  3. $translate->addTranslation(ROOT_DIR . '/modules/default/languages/english.php', 'en');
  4. $translate->setLocale(self$_lang);
  5. $this->view->translate()->setTranslator($translate);
  6. ?>


Poki co umieszczam go w metodzie init() kontrolera w ktorym wykorzystywane beda tlumaczenia.

Pozdrawiam

Ten post edytował batman 8.09.2008, 20:14:53
Powód edycji: dodałem bbcode ~batman
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
eai
post
Post #2





Grupa: Zarejestrowani
Postów: 367
Pomógł: 10
Dołączył: 20.05.2005

Ostrzeżenie: (0%)
-----


  1. <?php
  2. class Plugin_Translate extends Zend_Controller_Plugin_Abstract
  3. {
  4.    /**
  5.      * Plugin for translate
  6.      *
  7.      * @param Zend_Controller_Request_Abstract $request
  8.      */
  9.    public function routeStartup(Zend_Controller_Request_Abstract $request)
  10.    {
  11.        $translate = new Zend_Translate('array', ROOT_DIR . '/modules/default/languages/polish.php', 'pl');
  12.        $translate->addTranslation(ROOT_DIR . '/modules/default/languages/english.php', 'en');
  13.        $translate->setLocale(self$_lang);
  14.        $this->view->translate()->setTranslator($translate);
  15.  
  16.        Zend_Registryset('Zend_Translate', $translate);
  17.    }
  18. }
  19. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.10.2025 - 05:31