本文整理汇总了PHP中Zend_Translate::getAdapter方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Translate::getAdapter方法的具体用法?PHP Zend_Translate::getAdapter怎么用?PHP Zend_Translate::getAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Translate
的用法示例。
在下文中一共展示了Zend_Translate::getAdapter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setMessage
public static function setMessage(Zend_Translate $message)
{
if (!$message->getAdapter() instanceof Core_Translate_Message) {
throw new InvalidArgumentException('O adapter dever ser Core_Translate_Message');
}
static::set(static::MESSAGE, $message);
}
示例2: fileToDbAction
function fileToDbAction()
{
$translator = new Zend_Translate('ini', APPLICATION_PATH . '/languages/tran_en.ini', 'en');
$data = $translator->getAdapter()->getDataList();
foreach ($data['en'] as $key => $value) {
echo " {$key} => {$value}";
$ln = new Sys_Model_Translation();
$ln->setKey($key);
$ln->setEn($value);
$ln->save();
}
/*
$translator = new Zend_Translate('ini', APPLICATION_PATH . '/languages/tran_th.ini', 'en');
$data = ($translator->getAdapter()->getDataList());
foreach ($data['en'] as $key => $value){
echo " $key => $value";
$ln = new Sys_Model_Translation();
$ln->setKey($key);
$ln->setLanguage('EN');
$ln->setValue($value);
$ln->save();
}
*/
$this->_helper->redirector('index');
$this->render('blank', null, true);
}
示例3: setIniFilenameScanTranslator
public function setIniFilenameScanTranslator($path, $defaultLanguage, $language = null)
{
require_once 'Zend/Translate.php';
$translate = new Zend_Translate(Zend_Translate::AN_INI, $path, $defaultLanguage, array('scan' => Zend_Translate::LOCALE_FILENAME));
if ($translate->isAvailable($language)) {
$translate->setLocale($language);
}
$this->setTranslator($translate->getAdapter());
}
示例4: getTranslateAdapter
/**
* Returns a translate adaptor
*
* @return \Zend_Translate_Adapter
*/
protected function getTranslateAdapter()
{
if ($this->translate instanceof \Zend_Translate) {
return $this->translate->getAdapter();
}
if (!$this->translate instanceof \Zend_Translate_Adapter) {
$this->translate = new \MUtil_Translate_Adapter_Potemkin();
}
return $this->translate;
}
示例5: initTranslator
/**
* Set a static reference to a global Zend_Translate object
* usable through self::_() function
* If called more then one time, from the second call
* the $translator object will be appended to the previous one
* @param Zend_Translate $translator
*/
public static function initTranslator(Zend_Translate $translator)
{
//if ( true ) self::$_stringsWriter = new StringsWriter();
if (is_null(self::$_translator)) {
self::$_translator = $translator;
X_Debug::i("Translator enabled");
} else {
self::$_translator->getAdapter()->addTranslation($translator);
}
}
示例6: testSetAdapter
public function testSetAdapter()
{
$lang = new Zend_Translate(Zend_Translate::AN_GETTEXT, dirname(__FILE__) . '/Translate/_files/testmsg_en.mo', 'en');
$lang->setAdapter(Zend_Translate::AN_ARRAY, array());
$this->assertTrue($lang->getAdapter() instanceof Zend_Translate_Adapter_Array);
try {
$lang->xxxFunction();
$this->fail("exception expected");
} catch (Zend_Translate_Exception $e) {
// success
}
}
示例7: setTranslator
/**
* Sets a translation Adapter for translation
*
* @param Zend_Translate|Zend_Translate_Adapter $translate
* @return Zend_View_Helper_HeadTitle
*/
public function setTranslator($translate)
{
if ($translate instanceof Zend_Translate_Adapter) {
$this->_translator = $translate;
} elseif ($translate instanceof Zend_Translate) {
$this->_translator = $translate->getAdapter();
} else {
require_once 'Zend/View/Exception.php';
throw new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
}
return $this;
}
示例8: setTranslator
/**
* Sets a translation Adapter for translation
*
* @param Zend_Translate|Zend_Translate_Adapter $translate
* @return Zend_View_Helper_HeadTitle
*/
public function setTranslator($translate)
{
if ($translate instanceof Zend_Translate_Adapter) {
$this->_translator = $translate;
} elseif ($translate instanceof Zend_Translate) {
$this->_translator = $translate->getAdapter();
} else {
$e = new Zend_View_Exception("You must set an instance of Zend_Translate or Zend_Translate_Adapter");
$e->setView($this->view);
throw $e;
}
return $this;
}
示例9: setTranslator
/**
* Set translator
*
* @param Zend_Translate|Zend_Translate_Adapter|null $translator
* @return Zend_View_Helper_FormElement
*/
public function setTranslator($translator = null)
{
if (null === $translator) {
$this->_translator = null;
} elseif ($translator instanceof Zend_Translate_Adapter) {
$this->_translator = $translator;
} elseif ($translator instanceof Zend_Translate) {
$this->_translator = $translator->getAdapter();
} else {
$e = new Zend_View_Exception('Invalid translator specified');
$e->setView($this->view);
throw $e;
}
return $this;
}
示例10: _scanTranslations
/**
* Reads all available component translations and adds them to the translation object
*/
private function _scanTranslations()
{
// check for valid translation object
if (is_object($this->_translate)) {
foreach ($this->_extensionRegistry as $component => $settings) {
// check if component owns translation
if (isset($settings->languages) && is_readable($settings->path . $settings->languages)) {
// keep current locale
$locale = $this->_translate->getAdapter()->getLocale();
$this->_translate->addTranslation($settings->path . $settings->languages, null, array('scan' => Zend_Translate::LOCALE_FILENAME));
// reset current locale
$this->_translate->setLocale($locale);
}
}
}
}
示例11: initTranslateable
/**
* Function that checks the setup of this class/traight
*
* This function is not needed if the variables have been defined correctly in the
* source for this object and theose variables have been applied.
*
* return @void
*/
protected function initTranslateable()
{
if ($this->translateAdapter instanceof \Zend_Translate_Adapter) {
// OK
return;
}
if ($this->translate instanceof \Zend_Translate) {
// Just one step
$this->translateAdapter = $this->translate->getAdapter();
return;
}
if ($this->translate instanceof \Zend_Translate_Adapter) {
// It does happen and if it is all we have
$this->translateAdapter = $this->translate;
return;
}
// Make sure there always is an adapter, even if it is fake.
$this->translateAdapter = new \MUtil_Translate_Adapter_Potemkin();
}
示例12: setup
/**
* Setup
*
* @return void
*/
public function setup(Zend_Config $config)
{
// Setup Cache
if ($config->get('cache')) {
$cache = Zym_Cache::factory('Core');
Zend_Translate::setCache($cache);
}
$adapter = $config->get('adapter');
$data = $this->_parseDataPath($config->get('data'));
$locale = $config->get('locale');
$options = $this->_parseOptions($config->get('options')->toArray());
$translate = new Zend_Translate($adapter, $data, null, $options);
// Weird Zend_Translate issues
// We cannot set a locale in the constructor
$translate->getAdapter()->setLocale($locale);
if ((bool) $config->get('registry')->get('enabled')) {
/**
* @see Zend_Registry
*/
require_once 'Zend/Registry.php';
Zend_Registry::set($config->get('registry')->get('key'), $translate);
}
}
示例13: _initTranslation
/**
* init translation
*/
protected function _initTranslation()
{
try {
// init config
$this->bootstrap('config');
// init cache
$this->bootstrap('cache');
// init session
$this->bootstrap('session');
// get config
$config = Knowledgeroot_Registry::get('config');
// get cache
$cache = Knowledgeroot_Registry::get('cache');
// get session
$session = new Zend_Session_Namespace('user');
// check if session has a locale
$locale = null;
if (!empty($session->language)) {
$locale = $session->language;
} else {
$locale = $config->base->locale;
}
// load translations
$translate = new Knowledgeroot_Translation();
$translate->loadTranslations($config->translation->folder);
$translate->setLocale($locale);
// save in registry
Knowledgeroot_Registry::set('translate', $translate);
// create zend translate object
$zTranslate = new Zend_Translate(array('adapter' => 'gettext', 'content' => $translate->getLocaleFile(), 'locale' => $translate->getLocale()));
foreach ($translate->getTranslations() as $key => $value) {
$zTranslate->getAdapter()->addTranslation(array('adapter' => 'gettext', 'content' => $value, 'locale' => $key, 'clear' => false));
}
// set default locale
$zTranslate->getAdapter()->setLocale($locale);
// set cache
$zTranslate->setCache($cache);
// save in Zend_Translate in registry
Knowledgeroot_Registry::set('Zend_Translate', $zTranslate);
} catch (Zend_Exception $e) {
echo $e->getMessage();
die('no translation');
}
}
示例14: setTranslator
/**
* Sets a translation Adapter for translation
*
* @param Zend_Translate|Zend_Translate_Adapter $translate Instance of Zend_Translate
* @throws Zend_View_Exception When no or a false instance was set
* @return Zend_View_Helper_Translate
*/
public function setTranslator($translate)
{
if ($translate instanceof Zend_Translate_Adapter) {
$this->_translator = $translate;
} else {
if ($translate instanceof Zend_Translate) {
$this->_translator = $translate->getAdapter();
} else {
require_once 'Zend/View/Exception.php';
$e = new Zend_View_Exception('You must set an instance of Zend_Translate or Zend_Translate_Adapter');
$e->setView($this->view);
throw $e;
}
}
return $this;
}
示例15: setTranslator
/**
* Set translation object
*
* @param Zend_Translate|Zend\Translate\Adapter\Adapter|null $translator
* @return Zend\Filter\InputFilter
*/
public function setTranslator($translator = null)
{
if (null === $translator || $translator instanceof TranslationAdapter) {
$this->_translator = $translator;
} elseif ($translator instanceof Translator) {
$this->_translator = $translator->getAdapter();
} else {
throw new Validator\Exception('Invalid translator specified');
}
return $this;
}