本文整理汇总了PHP中Drupal::translation方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::translation方法的具体用法?PHP Drupal::translation怎么用?PHP Drupal::translation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal
的用法示例。
在下文中一共展示了Drupal::translation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: summaryTitle
/**
* {@inheritdoc}
*/
public function summaryTitle()
{
if ($this->options['vis']['manual_load']) {
return \Drupal::translation()->formatPlural($this->options['items_per_page'], 'Click to load, @count item', 'Click to load, @count items', array('@count' => $this->options['items_per_page']));
}
return \Drupal::translation()->formatPlural($this->options['items_per_page'], 'Infinite scroll, @count item', 'Infinite scroll, @count items', array('@count' => $this->options['items_per_page']));
}
示例2: generateElements
/**
* {@inheritdoc}
*/
protected function generateElements(array $values)
{
$num = $values['num'];
$kill = $values['kill'];
$pass = $values['pass'];
$age = $values['time_range'];
$roles = $values['roles'];
$url = parse_url($GLOBALS['base_url']);
if ($kill) {
$uids = db_select('users', 'u')->fields('u', array('uid'))->condition('uid', 1, '>')->execute()->fetchAllAssoc('uid');
user_delete_multiple(array_keys($uids));
$this->setMessage(\Drupal::translation()->formatPlural(count($uids), '1 user deleted', '@count users deleted.'));
}
if ($num > 0) {
$names = array();
while (count($names) < $num) {
//@todo add suport for devel_generate_word(mt_rand(6, 12)) in a class method
$name = $this->generateWord(mt_rand(6, 12));
$names[$name] = '';
}
if (empty($roles)) {
$roles = array(DRUPAL_AUTHENTICATED_RID);
}
foreach ($names as $name => $value) {
$edit = array('uid' => NULL, 'name' => $name, 'pass' => $pass, 'mail' => $name . '@example.com', 'status' => 1, 'created' => REQUEST_TIME - mt_rand(0, $age), 'roles' => array_combine($roles, $roles), 'devel_generate' => TRUE);
$account = entity_create('user', $edit);
// Populate all fields with sample values.
$this->populateFields($account);
$account->save();
}
}
$this->setMessage(t('!num_users created.', array('!num_users' => format_plural($num, '1 user', '@count users'))));
}
示例3: process
/**
* Processes fields targeted for purge as part of a configuration sync.
*
* This takes care of deleting the field if necessary, and purging the data on
* the fly.
*
* @param array $context
* The batch context.
* @param \Drupal\Core\Config\ConfigImporter $config_importer
* The config importer.
*/
public static function process(array &$context, ConfigImporter $config_importer)
{
if (!isset($context['sandbox']['field'])) {
static::initializeSandbox($context, $config_importer);
}
// Get the list of field storages to purge.
$field_storages = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete'));
// Get the first field storage to process.
$field_storage = reset($field_storages);
if (!isset($context['sandbox']['field']['current_storage_id']) || $context['sandbox']['field']['current_storage_id'] != $field_storage->id()) {
$context['sandbox']['field']['current_storage_id'] = $field_storage->id();
// If the storage has not been deleted yet we need to do that. This is the
// case when the storage deletion is staged.
if (!$field_storage->isDeleted()) {
$field_storage->delete();
}
}
field_purge_batch($context['sandbox']['field']['purge_batch_size'], $field_storage->uuid());
$context['sandbox']['field']['current_progress']++;
$fields_to_delete_count = count(static::getFieldStoragesToPurge($context['sandbox']['field']['extensions'], $config_importer->getUnprocessedConfiguration('delete')));
if ($fields_to_delete_count == 0) {
$context['finished'] = 1;
} else {
$context['finished'] = $context['sandbox']['field']['current_progress'] / $context['sandbox']['field']['steps_to_delete'];
$context['message'] = \Drupal::translation()->translate('Purging field @field_label', array('@field_label' => $field_storage->label()));
}
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(Schedule $entity)
{
$row['label'] = $entity->label();
$row['enabled'] = $entity->get('enabled') ? $this->t('Yes') : $this->t('No');
$row['period'] = $entity->getPeriodFormatted();
$row['last_run'] = $this->t('Never');
if ($last_run = $entity->getLastRun()) {
$row['last_run'] = \Drupal::service('date.formatter')->format($last_run, 'small');
$row['last_run'] .= ' (' . $this->t('@time ago', array('@time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $last_run))) . ')';
}
$row['next_run'] = $this->t('Not Scheduled');
if ($next_run = $entity->getNextRun()) {
$interval = \Drupal::service('date.formatter')->formatInterval(abs($next_run - REQUEST_TIME));
if ($next_run > REQUEST_TIME) {
$row['next_run'] = \Drupal::service('date.formatter')->format($next_run, 'small');
$row['next_run'] .= ' (' . $this->t('in @time', array('@time' => $interval)) . ')';
} else {
$row['next_run'] = $this->t('Next cron run');
if ($last_run) {
$row['next_run'] .= ' (' . $this->t('was due @time ago', array('@time' => $interval)) . ')';
}
}
}
$row['keep'] = \Drupal::translation()->formatPlural($entity->get('keep'), 'Last 1 backup', 'Last @count backups');
return $row + parent::buildRow($entity);
}
示例5: testUserLoginBlock
/**
* Test the user login block.
*/
function testUserLoginBlock()
{
// Make sure the validation error is displayed when try to login with
// invalid username/password.
$edit['name'] = $this->randomMachineName();
$edit['pass'] = $this->randomMachineName();
$this->drupalPostForm('node', $edit, t('Log in'));
$this->assertRaw(\Drupal::translation()->formatPlural(1, '1 error has been found: !errors', '@count errors have been found: !errors', ['!errors' => SafeMarkup::set('<a href="#edit-name">Username</a>')]));
$this->assertText(t('Sorry, unrecognized username or password.'));
// Create a user with some permission that anonymous users lack.
$user = $this->drupalCreateUser(array('administer permissions'));
// Log in using the block.
$edit = array();
$edit['name'] = $user->getUsername();
$edit['pass'] = $user->pass_raw;
$this->drupalPostForm('admin/people/permissions', $edit, t('Log in'));
$this->assertNoText(t('User login'), 'Logged in.');
// Check that we are still on the same page.
$this->assertUrl(\Drupal::url('user.admin_permissions', [], ['absolute' => TRUE]), [], 'Still on the same page after login for access denied page');
// Now, log out and repeat with a non-403 page.
$this->drupalLogout();
$this->drupalPostForm('filter/tips', $edit, t('Log in'));
$this->assertNoText(t('User login'), 'Logged in.');
$this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
// Check that the user login block is not vulnerable to information
// disclosure to third party sites.
$this->drupalLogout();
$this->drupalPostForm('http://example.com/', $edit, t('Log in'), array('external' => FALSE));
// Check that we remain on the site after login.
$this->assertUrl($user->url('canonical', ['absolute' => TRUE]), [], 'Redirected to user profile page after login from the frontpage');
}
示例6: doDisplay
protected function doDisplay(array $context, array $blocks = array())
{
// line 12
echo "<h3 class=\"views-ui-view-title views-table-filter-text-source\">";
echo $this->env->getExtension('drupal_core')->escapeFilter($this->env, $this->getAttribute(isset($context["view"]) ? $context["view"] : null, "label", array()), "html", null, true);
echo "</h3>\n<div class=\"views-ui-view-displays\">\n ";
// line 14
if (isset($context["displays"]) ? $context["displays"] : null) {
// line 15
echo " ";
echo \Drupal::translation()->formatPlural(abs(isset($context["displays"]) ? $context["displays"] : null), "Display", "Displays", array());
// line 19
echo ":\n <em>";
// line 20
echo $this->env->getExtension('drupal_core')->renderVar($this->env->getExtension('drupal_core')->safeJoin($this->env, isset($context["displays"]) ? $context["displays"] : null, ", "));
echo "</em>\n ";
} else {
// line 22
echo " ";
echo $this->env->getExtension('drupal_core')->renderVar(t("None"));
echo "\n ";
}
// line 24
echo "</div>\n<div class=\"views-ui-view-machine-name\">\n ";
// line 26
echo $this->env->getExtension('drupal_core')->renderVar(t("Machine name:"));
echo "\n <span class=\"views-table-filter-text-source\">";
// line 27
echo $this->env->getExtension('drupal_core')->escapeFilter($this->env, $this->getAttribute(isset($context["view"]) ? $context["view"] : null, "id", array()), "html", null, true);
echo "</span>\n</div>\n";
}
开发者ID:dmyerson,项目名称:d8ecs,代码行数:31,代码来源:77612430c4aab2039de68e28464de15491f92c9f1e54e2ea6fb95d6d5939ec05.php
示例7: testPiwikUninstall
/**
* Tests if the module cleans up the disk on uninstall.
*/
public function testPiwikUninstall()
{
$cache_path = 'public://piwik';
$site_id = '1';
$this->config('piwik.settings')->set('site_id', $site_id)->save();
$this->config('piwik.settings')->set('url_http', 'http://www.example.com/piwik/')->save();
$this->config('piwik.settings')->set('url_https', 'https://www.example.com/piwik/')->save();
// Enable local caching of piwik.js
$this->config('piwik.settings')->set('cache', 1)->save();
// Load front page to get the piwik.js downloaded into local cache. But
// loading the piwik.js is not possible as "url_http" is a test dummy only.
// Create a dummy file to complete the rest of the tests.
file_prepare_directory($cache_path, FILE_CREATE_DIRECTORY);
file_unmanaged_save_data($this->randomMachineName(16), $cache_path . '/piwik.js');
// Test if the directory and piwik.js exists.
$this->assertTrue(file_prepare_directory($cache_path), 'Cache directory "public://piwik" has been found.');
$this->assertTrue(file_exists($cache_path . '/piwik.js'), 'Cached piwik.js tracking file has been found.');
// Uninstall the module.
$edit = [];
$edit['uninstall[piwik]'] = TRUE;
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this->assertNoText(\Drupal::translation()->translate('Configuration deletions'), 'No configuration deletions listed on the module install confirmation page.');
$this->drupalPostForm(NULL, NULL, t('Uninstall'));
$this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
// Test if the directory and all files have been removed.
$this->assertFalse(file_scan_directory($cache_path, '/.*/'), 'Cached JavaScript files have been removed.');
$this->assertFalse(file_prepare_directory($cache_path), 'Cache directory "public://piwik" has been removed.');
}
示例8: testUninstallPage
/**
* Tests the Uninstall page and Uninstall confirmation page.
*/
function testUninstallPage()
{
$account = $this->drupalCreateUser(array('administer modules'));
$this->drupalLogin($account);
// Create a node type.
$node_type = entity_create('node_type', array('type' => 'uninstall_blocker', 'name' => 'Uninstall blocker'));
// Create a dependency that can be fixed.
$node_type->setThirdPartySetting('module_test', 'key', 'value');
$node_type->save();
// Add a node to prevent node from being uninstalled.
$node = entity_create('node', array('type' => 'uninstall_blocker'));
$node->save();
$this->drupalGet('admin/modules/uninstall');
$this->assertTitle(t('Uninstall') . ' | Drupal');
$this->assertText(\Drupal::translation()->translate('The following reasons prevents Node from being uninstalled: There is content for the entity type: Content'), 'Content prevents uninstalling node module.');
// Delete the node to allow node to be uninstalled.
$node->delete();
// Uninstall module_test.
$edit = array();
$edit['uninstall[module_test]'] = TRUE;
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this->assertNoText(\Drupal::translation()->translate('Configuration deletions'), 'No configuration deletions listed on the module install confirmation page.');
$this->assertText(\Drupal::translation()->translate('Configuration updates'), 'Configuration updates listed on the module install confirmation page.');
$this->assertText($node_type->label(), SafeMarkup::format('The entity label "!label" found.', array('!label' => $node_type->label())));
$this->drupalPostForm(NULL, NULL, t('Uninstall'));
$this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
// Uninstall node testing that the configuration that will be deleted is
// listed.
$node_dependencies = \Drupal::service('config.manager')->findConfigEntityDependentsAsEntities('module', array('node'));
$edit = array();
$edit['uninstall[node]'] = TRUE;
$this->drupalPostForm('admin/modules/uninstall', $edit, t('Uninstall'));
$this->assertText(\Drupal::translation()->translate('Configuration deletions'), 'Configuration deletions listed on the module install confirmation page.');
$this->assertNoText(\Drupal::translation()->translate('Configuration updates'), 'No configuration updates listed on the module install confirmation page.');
$entity_types = array();
foreach ($node_dependencies as $entity) {
$label = $entity->label() ?: $entity->id();
$this->assertText($label, SafeMarkup::format('The entity label "!label" found.', array('!label' => $label)));
$entity_types[] = $entity->getEntityTypeId();
}
$entity_types = array_unique($entity_types);
foreach ($entity_types as $entity_type_id) {
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
// Add h3's since the entity type label is often repeated in the entity
// labels.
$this->assertRaw('<h3>' . $entity_type->getLabel() . '</h3>');
}
// Set a unique cache entry to be able to test whether all caches are
// cleared during the uninstall.
\Drupal::cache()->set('uninstall_test', 'test_uninstall_page', Cache::PERMANENT);
$cached = \Drupal::cache()->get('uninstall_test');
$this->assertEqual($cached->data, 'test_uninstall_page', SafeMarkup::format('Cache entry found: @bin', array('@bin' => $cached->data)));
$this->drupalPostForm(NULL, NULL, t('Uninstall'));
$this->assertText(t('The selected modules have been uninstalled.'), 'Modules status has been updated.');
$this->assertNoRaw('<label', 'The page does not have double escaped HTML tags.');
// Make sure our unique cache entry is gone.
$cached = \Drupal::cache()->get('uninstall_test');
$this->assertFalse($cached, 'Cache entry not found');
}
示例9: transChoice
/**
* Implements \Symfony\Component\Translation\TranslatorInterface::transChoice().
*/
public function transChoice($id, $number, array $parameters = array(), $domain = NULL, $locale = NULL)
{
// Violation messages can separated singular and plural versions by "|".
$ids = explode('|', $id);
if (!isset($ids[1])) {
throw new \InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are @count apples").', $id));
}
return \Drupal::translation()->formatPlural($number, $ids[0], $ids[1], $this->processParameters($parameters), $this->getOptions($domain, $locale));
}
示例10: settingsSummary
/**
* {@inheritdoc}
*/
public function settingsSummary()
{
$summary = array();
if ($this->getSetting('open')) {
$summary[] = \Drupal::translation()->translate('Default state open');
} else {
$summary[] = \Drupal::translation()->translate('Default state closed');
}
return $summary;
}
示例11: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$num_nodes = $this->database->query("SELECT COUNT(*) FROM {crm_core_contact} WHERE type = :type", array(':type' => $this->entity->id()))->fetchField();
if ($num_nodes) {
$caption = \Drupal::translation()->formatPlural($num_nodes, '%type is used by one contact on your site. You can not remove this contact type until you have removed all of the %type contacts.', '%type is used by @count contacts on your site. You may not remove %type until you have removed all of the %type contacts.', array('%type' => $this->entity->label()));
$form['#title'] = $this->getQuestion();
$form['description'] = array('#markup' => '<p>' . $caption . '</p>');
return $form;
}
return parent::buildForm($form, $form_state);
}
示例12: settingsSummary
/**
* {@inheritdoc}
*/
public function settingsSummary()
{
$summary = array();
if ($this->getSetting('required_fields')) {
$summary[] = \Drupal::translation()->translate('Mark as required');
}
if ($this->getSetting('description')) {
$summary[] = \Drupal::translation()->translate('Description : @description', array('@description' => $this->getSetting('description')));
}
return $summary;
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$num_profiles = $this->queryFactory->get('profile')->condition('type', $this->entity->id())->count()->execute();
if ($num_profiles) {
$caption = '<p>' . \Drupal::translation()->formatPlural($num_profiles, '%type is used by 1 profile on your site. You can not remove this profile type until you have removed all of the %type profiles.', '%type is used by @count profiles on your site. You may not remove %type until you have removed all of the %type profiles.', ['%type' => $this->entity->label()]) . '</p>';
$form['#title'] = $this->entity->label();
$form['description'] = ['#markup' => $caption];
return $form;
}
return parent::buildForm($form, $form_state);
}
示例14: assertFileHookCalled
/**
* Assert that a hook_file_* hook was called a certain number of times.
*
* @param string $hook
* String with the hook name; for instance, 'load', 'save', 'insert', etc.
* @param int $expected_count
* Optional integer count.
* @param string|NULL $message
* Optional translated string message.
*/
function assertFileHookCalled($hook, $expected_count = 1, $message = NULL)
{
$actual_count = count(file_test_get_calls($hook));
if (!isset($message)) {
if ($actual_count == $expected_count) {
$message = format_string('hook_file_@name was called correctly.', array('@name' => $hook));
} elseif ($expected_count == 0) {
$message = \Drupal::translation()->formatPlural($actual_count, 'hook_file_@name was not expected to be called but was actually called once.', 'hook_file_@name was not expected to be called but was actually called @count times.', array('@name' => $hook, '@count' => $actual_count));
} else {
$message = format_string('hook_file_@name was expected to be called %expected times but was called %actual times.', array('@name' => $hook, '%expected' => $expected_count, '%actual' => $actual_count));
}
}
$this->assertEqual($actual_count, $expected_count, $message);
}
示例15: preRender
/**
* {@inheritdoc}
*/
public function preRender(&$element)
{
$add = array('#type' => 'details', '#id' => 'edit-' . $this->group->group_name, '#title' => String::checkPlain(\Drupal::translation()->translate($this->getLabel())), '#description' => $this->getSetting('description'));
if ($this->getSetting('classes')) {
$element['#attributes']['class'] = explode(' ', $this->getSetting('classes'));
}
// Front-end and back-end on configuration will lead
// to vertical tabs nested in a separate vertical group.
if (!empty($this->group->parent_name)) {
$add['#group'] = $this->group->parent_name;
$add['#parents'] = array($add['#group']);
}
$element += $add;
}