本文整理汇总了PHP中Translation::update方法的典型用法代码示例。如果您正苦于以下问题:PHP Translation::update方法的具体用法?PHP Translation::update怎么用?PHP Translation::update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translation
的用法示例。
在下文中一共展示了Translation::update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSingleItem
public function testSingleItem()
{
Translation::update('Model.1.field', 'Updated foo');
Translation::update('Model.1.another_field', 'Updated bar');
$in = array(array('Model' => array('id' => 1, 'field' => 'foo', 'another_field' => 'bar'), 'AnotherModel' => array('id' => 2, 'field' => 'foo', 'another_field' => 'bar')));
$iterator = new TranslateInjector($in, array('Model.field', 'Model.another_field'), array('modelAlias' => 'Model', 'modelName' => 'Model'));
$data = iterator_to_array($iterator);
$expected = array(array('Model' => array('id' => 1, 'field' => 'Updated foo', 'another_field' => 'Updated bar'), 'AnotherModel' => array('id' => 2, 'field' => 'foo', 'another_field' => 'bar')));
$this->assertSame($expected, $data);
}
示例2: testReadTranslation
/**
* testReadTranslation
*
* Reading a translated field value should return the translated value
*
* @return void
*/
public function testReadTranslation()
{
Translation::update('Tag.1.tag', 'Foo', array('domain' => 'data'));
Translation::update('Tag.3.tag', 'Zum', array('domain' => 'data'));
$expected = array(1 => 'Foo', 'tag2', 'Zum');
$result = $this->Tag->find('list');
$this->assertSame($expected, $result);
Translation::update('Tag.2.tag', 'Bar', array('domain' => 'data'));
$expected = array(1 => 'Foo', 'Bar', 'Zum');
$result = $this->Tag->find('list');
$this->assertSame($expected, $result);
}
示例3:
echo Config::toJSON(Translation::translations());
break;
/**
@param $_GET['TranslationId']
@param $_GET['Payload'] The payload that determines what will be updated.
@param $_GET['Update'] The update value to write
@param $_GET['Provider'] The Provider to perform the update to
*/
/**
@param $_GET['TranslationId']
@param $_GET['Payload'] The payload that determines what will be updated.
@param $_GET['Update'] The update value to write
@param $_GET['Provider'] The Provider to perform the update to
*/
case 'update':
Translation::update($_GET['TranslationId'], $_GET['Payload'], $_GET['Update'], $_GET['Provider']);
break;
/**
@param Req
@param Description
*/
/**
@param Req
@param Description
*/
case 'updateDescription':
Translation::updateDescription($_GET['Req'], $_GET['Description']);
break;
/**
@param TranslationId
@param TranslationName
示例4: afterSave
/**
* afterSave Callback
*
* Loop on pending translations, and update translations
*
* @param Model $Model Model the callback is called on
* @param boolean $created Whether or not the save created a record.
* @return void */
public function afterSave(Model $Model, $created)
{
if ($this->_pendingTranslations) {
foreach ($this->_pendingTranslations as $locale => $translations) {
$params = array('domain' => $this->settings[$Model->alias]['domain'], 'locale' => $locale, 'autoPopulate' => true);
foreach ($translations as $key => $value) {
if (strpos($key, '{') !== false) {
if (!$Model->id) {
continue;
}
$key = String::insert($key, array('id' => $Model->id), array('before' => '{', 'after' => '}'));
}
Translation::update($key, $value, $params);
}
}
$this->_pendingTranslations = array();
}
}
示例5: _translate
/**
* _translate
*
* Translate one field value. If there is no translation at all - return the original
*
* @param string $key
* @param string $value
* @return string
*/
protected function _translate($key, $value, $id)
{
$field = preg_replace('@.*\\.@', '', $key);
$key = sprintf('%s.%s.%s', $this->_settings['modelName'], $id, $field);
$translated = Translation::translate($key, array('domain' => $this->_settings['domain']));
if ($translated === $key) {
Translation::update($key, $value, array('locale' => Configure::read('Config.defaultLanguage'), 'domain' => $this->_settings['domain']));
return $value;
}
return $translated;
}
示例6: testAddActionTranslatedDefaultDomain
/**
* testAddActionTranslatedDefaultDomain
*
* Simulate the controller's components array having defined the default domain for crud messages
* Verify that that is the default domain is used for the crud translations
*
* @return void
*/
public function testAddActionTranslatedDefaultDomain()
{
$this->skipIf(!class_exists('Translation'), 'Test depends on the Translations plugin');
$translatedMessage = 'eksemplet blev oprettet med succes';
Translation::update('Successfully created CrudExample', $translatedMessage);
$this->assertSame($translatedMessage, __d('default', 'Successfully created CrudExample'));
Router::connect("/:action", array('controller' => 'crud_examples'));
CrudExamplesController::$componentsArray['Crud.Crud']['translations']['domain'] = 'default';
$this->Controller = $this->generate('CrudExamples', array('methods' => array('header', 'redirect', 'render'), 'components' => array('Session')));
$this->Controller->Session->expects($this->once())->method('setFlash')->with($translatedMessage);
$this->testAction('/add', array('data' => array('CrudExample' => array('title' => __METHOD__, 'description' => __METHOD__, 'author_id' => 0))));
}
示例7: employeeSettingsAction
public function employeeSettingsAction()
{
require_once 'models/table/System.php';
$sysTable = new System();
// For "Labels"
// same logic as other Settings pages - except the employee_header setting below
require_once 'models/table/Translation.php';
$labelNames = array('label_partner' => 'Partner', 'label_sub_partner' => 'Sub Partner', 'label_type' => 'Type of Partner', 'label_funder' => 'Funder', 'label_full_time' => 'Full Time', 'label_base' => 'Employee Based at', 'label_funded_hours_per_week' => 'Funded hours per week', 'label_cadre' => 'Staff Cadre', 'label_staff_category' => 'Staff Category', 'label_annual_cost' => 'Annual Cost', 'label_primary_role' => 'Primary Role', 'label_importance' => 'Importance', 'label_intended_transition' => 'Intended Transition', 'label_incoming_partner' => 'Incoming partner', 'label_relationship' => 'Relationship', 'label_referral_mechanism' => 'Referral Mechanism', 'label_chw_supervisor' => 'CHW Supervisor', 'label_trainings_provided' => 'Trainings provided', 'label_courses_completed' => 'Courses Completed', 'label_other_id' => 'Other ID', 'label_disability' => 'Disability', 'label_disability_comments' => 'Disability Comments', 'label_nationality' => 'Employee Nationality', 'label_race' => 'Race', 'label_registration_number' => 'Registration Number', 'label_salary' => 'Salary', 'label_benefits' => 'Benefits', 'label_additional_expenses' => 'Additional Expenses', 'label_stipend' => 'Stipend');
$checkboxFields = array('check_partner' => 'display_employee_partner', 'check_sub_partner' => 'display_employee_sub_partner', 'check_type' => 'display_partner_type', 'check_funder' => 'display_employee_funder', 'check_full_time' => 'display_employee_full_time', 'check_base' => 'display_employee_base', 'check_site_type' => 'display_employee_site_type', 'check_funded_hours_per_week' => 'display_employee_funded_hours_per_week', 'check_staff_category' => 'display_employee_staff_category', 'check_annual_cost' => 'display_employee_annual_cost', 'check_primary_role' => 'display_employee_primary_role', 'check_importance' => 'display_employee_importance', 'check_contract_end_date' => 'display_employee_contract_end_date', 'check_agreement_end_date' => 'display_employee_agreement_end_date', 'check_intended_transition' => 'display_employee_intended_transition', 'check_transition_confirmed' => 'display_employee_transition_confirmed', 'check_transition_complete' => 'display_employee_complete_transition', 'check_transition_complete_date' => 'display_employee_actual_transition_date', 'check_incoming_partner' => 'display_employee_incoming_partner', 'check_relationship' => 'display_employee_relationship', 'check_referral_mechanism' => 'display_employee_referral_mechanism', 'check_chw_supervisor' => 'display_employee_chw_supervisor', 'check_trainings_provided' => 'display_employee_trainings_provided', 'check_courses_completed' => 'display_employee_courses_completed', 'check_site_name' => 'display_employee_site_name', 'check_employee_header' => 'display_employee_employee_header', 'check_other_id' => 'display_employee_other_id', 'check_disability' => 'display_employee_disability', 'check_nationality' => 'display_employee_nationality', 'check_race' => 'display_employee_race', 'check_registration_number' => 'display_employee_registration_number', 'check_salary' => 'display_employee_salary', 'check_benefits' => 'display_employee_benefits', 'check_additional_expenses' => 'display_employee_additional_expenses', 'check_stipend' => 'display_employee_stipend');
if ($this->getRequest()->isPost()) {
// Update db
$updateData = array();
// update translation labels
$tranTable = new Translation();
foreach ($labelNames as $input_key => $db_key) {
if ($this->_getParam($input_key)) {
try {
$tranTable->update(array('phrase' => $this->_getParam($input_key)), "key_phrase = '{$db_key}'");
$this->viewAssignEscaped($input_key, $this->_getParam($input_key));
} catch (Zend_Exception $e) {
error_log($e);
}
}
}
// update _system (checkboxes)
foreach ($checkboxFields as $input_key => $db_field) {
$value = $this->_getParam($input_key) == NULL ? 0 : 1;
$updateData[$db_field] = $value;
$this->view->assign($input_key, $value);
}
$updateData['employee_header'] = $this->_getParam('employee_header');
$this->view->assign('employee_header', $this->_getParam('employee_header') ? $this->_getParam('employee_header') : '');
$sysTable->update($updateData, '');
} else {
// view
// checkboxes
$sysRows = $sysTable->fetchRow($sysTable->select()->limit(1));
$this->view->assign('employee_header', isset($sysRows->employee_header) ? $sysRows->employee_header : '');
foreach ($checkboxFields as $input_key => $field_key) {
if (isset($sysRows->{$field_key})) {
$this->view->assign($input_key, $sysRows->{$field_key});
}
}
// labels
$t = Translation::getAll();
foreach ($labelNames as $input_key => $db_key) {
$this->viewAssignEscaped($input_key, $t[$db_key]);
}
}
// redirect to next page
if ($this->_getParam('redirect')) {
header("Location: " . $this->_getParam('redirect'));
exit;
} else {
if ($this->_getParam('saveonly')) {
$status = ValidationContainer::instance();
$status->setStatusMessage(t('Your settings have been updated.'));
}
}
}