本文整理匯總了PHP中Translation::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP Translation::add方法的具體用法?PHP Translation::add怎麽用?PHP Translation::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Translation
的用法示例。
在下文中一共展示了Translation::add方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: setTranslations
/**
* Sets translation in database
*
* @param string $codeName the code naeme to add/update/delete
* @param array $translationList array like array('en' => 'enValue', 'fr' => 'deValue')
*/
public static function setTranslations($codeName, $translationList)
{
if (empty($translationList)) {
return;
}
foreach ($translationList as $language => $translation) {
// If translation text is null, removes the entry
if ($translation === NULL) {
ElementFactory::deleteElementList('Translation', 'translation_text=\'' . $codeName . '\' AND translation_language=\'' . $language . '\'');
continue;
}
try {
$translationElement = ElementFactory::getElement('Translation', NULL, 'translation_text=\'' . $codeName . '\' AND translation_language=\'' . $language . '\'');
$translationElement->value = $translation;
$translationElement->update();
} catch (ElementNoResultException $e) {
$translationElement = new Translation();
$translationElement->language = $language;
$translationElement->text = $codeName;
$translationElement->value = $translation;
$translationElement->add();
}
}
}
示例2: onSubmit
function onSubmit($vals)
{
$collection = $vals['_collection'];
$status = $vals['_status'];
$key = $vals['_key'];
$lang = $vals['_lang'];
unset($vals['_collection']);
unset($vals['_status']);
unset($vals['_key']);
unset($vals['_lang']);
unset($vals['_header']);
unset($vals['submit_button']);
foreach ($vals as $k => $v) {
if (empty($v)) {
unset($vals[$k]);
}
}
$tr = new Translation($collection, $lang);
$id = $tr->getID($key);
if (!$id) {
$tr->add($key, $status, $vals);
} else {
$tr->save($key, $status, $vals);
}
page_title(intl_get('Translation Saved'));
echo '<p><a href="' . site_prefix() . '/index/multilingual-app">' . intl_get('Continue') . '</a></p>';
}