本文整理汇总了PHP中Zend_Translate::isTranslated方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Translate::isTranslated方法的具体用法?PHP Zend_Translate::isTranslated怎么用?PHP Zend_Translate::isTranslated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Translate
的用法示例。
在下文中一共展示了Zend_Translate::isTranslated方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translate
/**
* Retturn translation string
* example $l->translate('Field %1 is incorrect', 'FieldName');
*
* @param string $msg Message to transalte.
*/
public function translate($msg)
{
$translated = $msg;
if ($this->translate->isTranslated($msg, true, $this->locale)) {
$translated = $this->translate->translate($msg);
} else {
foreach ($this->translationsPaths as $name => $value) {
if (!$this->translate->isAvailable($name)) {
try {
$this->translate->addTranslation($this->translationsPaths[$name], $name);
$this->translate->setLocale($this->getLocale());
} catch (Zend_Translate_Exception $e) {
continue;
}
}
if ($this->translate->isTranslated($msg, $name)) {
$translated = $this->translate->translate($msg, $name);
break;
}
}
}
if (func_num_args() > 1) {
$params = func_get_args();
$params[0] = $translated;
$translated = @call_user_func_array("sprintf", $params);
//add shield for incorrect translations(warning about incorrect number of arguments)
}
return $translated;
}
示例2: translate
static function translate($locale_code, $module_name, $key, $replace = null, $do_translation = true) {
// DON'T EVER LEAVE THIS UNCOMMENTED
// ob_clean();
// can be useful for debugging since using dd() will dump out into the existing markup and be hard to see
// but this clears out all the other markup so the debug data can be seen clearly
$translation = $key;
if ($do_translation) {
if (RivetyCore_Registry::get('enable_localization') == '1'
&& !is_null($module_name) && trim($module_name) != ""
&& !is_null($key) && trim($key) != "") {
$locale_code = RivetyCore_Translate::cleanZendLocaleCode($locale_code);
// TODO: account for core rivety module
$path_to_csv = RivetyCore_Registry::get('basepath')."/modules/".$module_name."/languages/".$locale_code.".csv";
if (file_exists($path_to_csv)) {
try {
$translate = new Zend_Translate("csv", $path_to_csv, $locale_code, array('delimiter' => ","));
$translation = $translate->_($key);
// this next bit will populate the locale file with untranslated terms
// so it's easier for someone to go through and translate them
if (RivetyCore_Registry::get('auto_populate_language_files') == '1') {
if (!$translate->isTranslated($key, true, $locale_code)) {
$key_no_quotes = str_replace('"', '"', $key);
$str = '"'.$key_no_quotes.'","'.$key_no_quotes.'"'."\n";
file_put_contents($path_to_csv, $str, FILE_APPEND);
}
}
} catch (Exception $e) {
$translation = $key;
}
} else {
// create the file
file_put_contents($path_to_csv, $key.','.$key);
}
}
}
$output = "";
if (is_null($replace)) {
// no replace, no sprintf
$output = $translation;
} else {
if (is_array($replace)) {
if (count($replace) > 1) {
// there are multiple indices, use vsprintf
$output = vsprintf($translation, $replace);
} else {
// there's only one index, use the cheaper sprintf instead
$output = sprintf($translation, $replace[0]);
}
} else {
// $replace is not an array, so try using it straight
$output = sprintf($translation, $replace);
}
}
return $output;
}
示例3: testTranslationOfLanguages
public function testTranslationOfLanguages()
{
$languages = Opus_Language::getAll();
foreach ($languages as $language) {
$key = $language->getPart2T();
$this->assertTrue($this->translate->isTranslated($key), $key);
}
}
示例4: isTranslated
/**
* Checks if a string is translatable
*
* @param string $message
*
* @return mixed
*/
public function isTranslated($message)
{
if (strlen($message) == 0) {
return false;
}
if ($this->getTranslator()) {
return $this->_translator->isTranslated($message);
}
return false;
}
示例5: getValues
public static function getValues(Zend_Translate $lang)
{
$vars = Unsee_Hash::$ttlTypes;
$values = array();
foreach ($vars as $item) {
$elLangString = 'settings_delete_ttl_' . $item;
if ($lang->isTranslated($elLangString)) {
$values[$item] = $lang->translate($elLangString);
}
}
return $values;
}
示例6: testAddingAdapterToSourceUsingOwnRule
/**
* @group ZF-9489
*/
public function testAddingAdapterToSourceUsingOwnRule()
{
$translate = new Zend_Translate(Zend_Translate::AN_ARRAY, array('singular' => array('plural_0 (en)', 'plural_1 (en)', 'plural_2 (en)', 'plural_3 (en)'), 'plural' => ''), 'en');
$this->assertFalse($translate->isTranslated('Message 1'));
$adapter = new Zend_Translate_Adapter_Gettext(dirname(__FILE__) . '/Translate/Adapter/_files/translation_en.mo', 'en');
$translate->addTranslation($adapter);
$this->assertTrue($adapter->isTranslated('Message 1'));
$adapter2 = new Zend_Translate_Adapter_Gettext(dirname(__FILE__) . '/Translate/Adapter/_files/testmo/de_AT/LC_TEST/translation-de_DE.mo', 'de_AT');
$adapter2->addTranslation(dirname(__FILE__) . '/Translate/Adapter/_files/translation_en2.mo', 'fr');
$translate->addTranslation($adapter2, 'fr');
$languages = $translate->getList();
$this->assertFalse(array_key_exists('de_AT', $languages));
$this->assertTrue(array_key_exists('fr', $languages));
}
示例7: catch
$translate->addTranslation('../languages/it/webacula_it.mo', 'it');
$translate->addTranslation('../languages/es/webacula_es.mo', 'es');
$translate->addTranslation('../languages/cs/webacula_cs.mo', 'cs');
if (isset($config->general->locale)) {
// locale is user defined
$locale = new Zend_Locale(trim($config->general->locale));
} else {
// autodetect locale
// Search order is: given Locale, HTTP Client, Server Environment, Framework Standard
try {
$locale = new Zend_Locale('auto');
} catch (Zend_Locale_Exception $e) {
$locale = new Zend_Locale('en');
}
}
if ($translate->isTranslated('Desktop', false, $locale)) {
// can be translated (есть перевод)
$translate->setLocale($locale);
} else {
// can't translated (нет перевода)
// set to English by default
$translate->setLocale('en');
$locale = new Zend_Locale('en');
}
// assign the $translate object to the registry so that it can be retrieved elsewhere in the application
$registry->set('translate', $translate);
$registry->set('locale', $locale);
$registry->set('language', $locale->getLanguage());
// Show human readable short Job description instead of Job Bacula names
if (isset($config->general->show_job_description)) {
if ($config->general->show_job_description < 0 || $config->general->show_job_description > 2) {
示例8: testIsTranslated
public function testIsTranslated()
{
$lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array('msg1' => 'Message 1 (en)'), 'en_US');
$this->assertTrue($lang->isTranslated('msg1'));
$this->assertFalse($lang->isTranslated('msg2'));
$this->assertFalse($lang->isTranslated('msg1', false, 'en'));
$this->assertFalse($lang->isTranslated('msg1', true, 'en'));
$this->assertFalse($lang->isTranslated('msg1', false, 'ru'));
}
示例9: testDontLogUntranslatedMessageWithIsTranslated
/**
* ZF-7508
*/
public function testDontLogUntranslatedMessageWithIsTranslated()
{
$lang = new Zend_Translate(Zend_Translate::AN_CSV, dirname(__FILE__) . '/Translate/Adapter/_files', 'en', array('delimiter' => ','));
$this->assertFalse($lang->isTranslated('ignored'));
$stream = fopen('php://memory', 'w+');
require_once 'Zend/Log/Writer/Stream.php';
$writer = new Zend_Log_Writer_Stream($stream);
require_once 'Zend/Log.php';
$log = new Zend_Log($writer);
$lang->setOptions(array('logUntranslated' => true, 'log' => $log));
$this->assertFalse($lang->isTranslated('ignored'));
rewind($stream);
$this->assertNotContains('ignored', stream_get_contents($stream));
}