本文整理汇总了PHP中language_list函数的典型用法代码示例。如果您正苦于以下问题:PHP language_list函数的具体用法?PHP language_list怎么用?PHP language_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了language_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: summary
/**
* {@inheritdoc}
*/
public function summary()
{
$language_list = language_list(LanguageInterface::STATE_ALL);
$selected = $this->configuration['langcodes'];
// Reduce the language list to an array of language names.
$language_names = array_reduce($language_list, function (&$result, $item) use($selected) {
// If the current item of the $language_list array is one of the selected
// languages, add it to the $results array.
if (!empty($selected[$item->getId()])) {
$result[$item->getId()] = $item->name;
}
return $result;
}, array());
// If we have more than one language selected, separate them by commas.
if (count($this->configuration['langcodes']) > 1) {
$languages = implode(', ', $language_names);
} else {
// If we have just one language just grab the only present value.
$languages = array_pop($language_names);
}
if (!empty($this->configuration['negate'])) {
return t('The language is not @languages.', array('@languages' => $languages));
}
return t('The language is @languages.', array('@languages' => $languages));
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form = array();
// Initialize a language list to the ones available, including English.
$languages = language_list();
$existing_languages = array();
foreach ($languages as $langcode => $language) {
$existing_languages[$langcode] = $language->name;
}
// If we have no languages available, present the list of predefined languages
// only. If we do have already added languages, set up two option groups with
// the list of existing and then predefined languages.
if (empty($existing_languages)) {
$language_options = $this->languageManager->getStandardLanguageListWithoutConfigured();
} else {
$language_options = array($this->t('Existing languages') => $existing_languages, $this->t('Languages not yet added') => $this->languageManager->getStandardLanguageListWithoutConfigured());
}
$form['mappings'] = array('#tree' => TRUE, '#theme' => 'language_negotiation_configure_browser_form_table');
$mappings = $this->language_get_browser_drupal_langcode_mappings();
foreach ($mappings as $browser_langcode => $drupal_langcode) {
$form['mappings'][$browser_langcode] = array('browser_langcode' => array('#type' => 'textfield', '#default_value' => $browser_langcode, '#size' => 20, '#required' => TRUE), 'drupal_langcode' => array('#type' => 'select', '#options' => $language_options, '#default_value' => $drupal_langcode, '#required' => TRUE));
}
// Add empty row.
$form['new_mapping'] = array('#type' => 'details', '#title' => $this->t('Add a new mapping'), '#tree' => TRUE);
$form['new_mapping']['browser_langcode'] = array('#type' => 'textfield', '#title' => $this->t('Browser language code'), '#description' => $this->t('Use language codes as <a href="@w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', array('@w3ctags' => 'http://www.w3.org/International/articles/language-tags/')), '#default_value' => '', '#size' => 20);
$form['new_mapping']['drupal_langcode'] = array('#type' => 'select', '#title' => $this->t('Drupal language'), '#options' => $language_options, '#default_value' => '');
return parent::buildForm($form, $form_state);
}
示例3: getManagedTargets
public function getManagedTargets($as_detailed_objects = FALSE)
{
lingotek_add_missing_locales();
// fills in any missing lingotek_locale values to the languages table
$targets_drupal = language_list();
$default_language = language_default();
$targets = array();
foreach ($targets_drupal as $key => $target) {
$is_source = $default_language->language == $target->language;
$is_lingotek_managed = $target->lingotek_enabled;
if ($is_source) {
continue;
// skip, since the source language is not a target
} else {
if (!$is_lingotek_managed) {
continue;
// skip, since lingotek is not managing the language
}
}
$target->active = $target->lingotek_enabled;
$targets[$key] = $target;
}
$result = $as_detailed_objects ? $targets : array_map(create_function('$obj', 'return $obj->lingotek_locale;'), $targets);
return $result;
}
示例4: __construct
function __construct($path)
{
parent::__construct($path);
$this->filename = 'sitemap_images';
$this->node_image_loader = new NodeImagesLoader();
$this->available_langs = language_list();
}
示例5: deliver
/**
* Override parent deliver() function.
*/
public function deliver(array $output = array())
{
$plugin = $this->plugin;
$message = $this->message;
$options = $plugin['options'];
$account = user_load($message->uid);
$mail = !empty($options['mail']) ? $options['mail'] : $account->mail;
$languages = language_list();
if (!$options['language override']) {
$lang = !empty($account->language) && $account->language != LANGUAGE_NONE ? $languages[$account->language] : language_default();
} else {
$lang = $languages[$message->language];
}
// The subject in an email can't be with HTML, so strip it.
$output['message_notify_email_subject'] = strip_tags($output['message_notify_email_subject']);
// Allow for overriding the 'from' of the message.
$from = isset($options['from']) ? $options['from'] : NULL;
$from_account = !empty($message->user->uid) ? user_load($message->user->uid) : $account;
$mimemail_name = variable_get('mimemail_name', t('Atrium'));
$from = array('name' => oa_core_realname($from_account) . ' (' . $mimemail_name . ')', 'mail' => is_array($from) ? $from['mail'] : $from);
// Pass the message entity along to hook_drupal_mail().
$output['message_entity'] = $message;
if (!empty($message->email_attachments)) {
$output['attachments'] = isset($output['attachments']) ? $output['attachments'] : array();
$output['attachments'] = array_merge($message->email_attachments, $output['attachments']);
}
return drupal_mail('message_notify', $message->type, $mail, $lang, $output, $from);
}
示例6: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$filter_values = $this->translateFilterValues();
$langcode = $filter_values['langcode'];
$this->languageManager->reset();
$languages = language_list();
$langname = isset($langcode) ? $languages[$langcode]->name : "- None -";
$form['#attached']['library'][] = 'locale/drupal.locale.admin';
$form['langcode'] = array('#type' => 'value', '#value' => $filter_values['langcode']);
$form['strings'] = array('#type' => 'item', '#tree' => TRUE, '#language' => $langname, '#theme' => 'locale_translate_edit_form_strings');
if (isset($langcode)) {
$strings = $this->translateFilterLoadStrings();
$plural_formulas = $this->state->get('locale.translation.plurals') ?: array();
foreach ($strings as $string) {
// Cast into source string, will do for our purposes.
$source = new SourceString($string);
// Split source to work with plural values.
$source_array = $source->getPlurals();
$translation_array = $string->getPlurals();
if (count($source_array) == 1) {
// Add original string value and mark as non-plural.
$form['strings'][$string->lid]['plural'] = array('#type' => 'value', '#value' => 0);
$form['strings'][$string->lid]['original'] = array('#type' => 'item', '#title' => $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))), '#title_display' => 'invisible', '#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>');
} else {
// Add original string value and mark as plural.
$form['strings'][$string->lid]['plural'] = array('#type' => 'value', '#value' => 1);
$form['strings'][$string->lid]['original_singular'] = array('#type' => 'item', '#title' => $this->t('Singular form'), '#markup' => '<span lang="en">' . String::checkPlain($source_array[0]) . '</span>', '#prefix' => '<span class="visually-hidden">' . $this->t('Source string (@language)', array('@language' => $this->t('Built-in English'))) . '</span>');
$form['strings'][$string->lid]['original_plural'] = array('#type' => 'item', '#title' => $this->t('Plural form'), '#markup' => '<span lang="en">' . String::checkPlain($source_array[1]) . '</span>');
}
if (!empty($string->context)) {
$form['strings'][$string->lid]['context'] = array('#type' => 'value', '#value' => '<span lang="en">' . String::checkPlain($string->context) . '</span>');
}
// Approximate the number of rows to use in the default textarea.
$rows = min(ceil(str_word_count($source_array[0]) / 12), 10);
if (empty($form['strings'][$string->lid]['plural']['#value'])) {
$form['strings'][$string->lid]['translations'][0] = array('#type' => 'textarea', '#title' => $this->t('Translated string (@language)', array('@language' => $langname)), '#title_display' => 'invisible', '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode));
} else {
// Dealing with plural strings.
if (isset($plural_formulas[$langcode]['plurals']) && $plural_formulas[$langcode]['plurals'] > 2) {
// Add a textarea for each plural variant.
for ($i = 0; $i < $plural_formulas[$langcode]['plurals']; $i++) {
$form['strings'][$string->lid]['translations'][$i] = array('#type' => 'textarea', '#title' => $i == 0 ? $this->t('Singular form') : format_plural($i, 'First plural form', '@count. plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', '#attributes' => array('lang' => $langcode), '#prefix' => $i == 0 ? '<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>' : '');
}
} else {
// Fallback for unknown number of plurals.
$form['strings'][$string->lid]['translations'][0] = array('#type' => 'textarea', '#title' => $this->t('Singular form'), '#rows' => $rows, '#default_value' => $translation_array[0], '#attributes' => array('lang' => $langcode), '#prefix' => '<span class="visually-hidden">' . $this->t('Translated string (@language)', array('@language' => $langname)) . '</span>');
$form['strings'][$string->lid]['translations'][1] = array('#type' => 'textarea', '#title' => $this->t('Plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '', '#attributes' => array('lang' => $langcode));
}
}
}
if (count(Element::children($form['strings']))) {
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save translations'));
}
}
return $form;
}
示例7: addFilterWidget
public function addFilterWidget(&$form, &$form_state, $form_id)
{
if ($this->active) {
$options = array('' => t('-- Current (@lang) --', array('@lang' => t($GLOBALS['language']->name))), 'all' => t('-- All --'));
foreach (language_list() as $key => $lang) {
$options[$key] = t($lang->name);
}
$form['langselect'] = array('#type' => 'select', '#title' => t('Filter menu by language'), '#options' => $options, '#default_value' => $this->language, '#ajax' => array('callback' => '_content_menu_filter_elements_by_language'));
$form['#content_menu_filter_widget'][] = 'langselect';
}
}
示例8: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
// Prepare a language object for saving.
$languages = language_list();
$langcode = $form_state['values']['langcode'];
$language = $languages[$langcode];
$language->name = $form_state['values']['name'];
$language->direction = $form_state['values']['direction'];
language_save($language);
$form_state->setRedirect('language.admin_overview');
}
示例9: pdt_cookie_consent_form
/**
* Formulaire de config multilingue, drupal 7
* @return mixed
*/
function pdt_cookie_consent_form()
{
$form = array();
$languages = language_list();
foreach ($languages as $language) {
$lang = $language->language;
$form[$lang] = array('#type' => "fieldset", '#title' => "Configuration pour le language " . $lang);
$form[$lang]["pdt_cookie_consent_message_{$lang}"] = array('#title' => 'Message', '#type' => 'textfield', '#description' => '', '#default_value' => variable_get("pdt_cookie_consent_message_{$lang}", ""));
}
return system_settings_form($form);
}
示例10: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state)
{
// Prepare a language object for saving.
$languages = language_list();
$langcode = $form_state['values']['langcode'];
$language = $languages[$langcode];
$language->name = $form_state['values']['name'];
$language->direction = $form_state['values']['direction'];
language_save($language);
$form_state['redirect_route']['route_name'] = 'language.admin_overview';
}
示例11: validateForm
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
$languages = language_list();
// Count repeated values for uniqueness check.
$count = array_count_values($form_state->getValue('prefix'));
foreach ($languages as $langcode => $language) {
$value = $form_state->getValue(array('prefix', $langcode));
if ($value === '') {
if (!$language->isDefault() && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
// Throw a form error if the prefix is blank for a non-default language,
// although it is required for selected negotiation type.
$form_state->setErrorByName("prefix][{$langcode}", $this->t('The prefix may only be left blank for the default language.'));
}
} elseif (strpos($value, '/') !== FALSE) {
// Throw a form error if the string contains a slash,
// which would not work.
$form_state->setErrorByName("prefix][{$langcode}", $this->t('The prefix may not contain a slash.'));
} elseif (isset($count[$value]) && $count[$value] > 1) {
// Throw a form error if there are two languages with the same
// domain/prefix.
$form_state->setErrorByName("prefix][{$langcode}", $this->t('The prefix for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value)));
}
}
// Count repeated values for uniqueness check.
$count = array_count_values($form_state->getValue('domain'));
foreach ($languages as $langcode => $language) {
$value = $form_state->getValue(array('domain', $langcode));
if ($value === '') {
if ($form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_DOMAIN) {
// Throw a form error if the domain is blank for a non-default language,
// although it is required for selected negotiation type.
$form_state->setErrorByName("domain][{$langcode}", $this->t('The domain may not be left blank for %language.', array('%language' => $language->name)));
}
} elseif (isset($count[$value]) && $count[$value] > 1) {
// Throw a form error if there are two languages with the same
// domain/domain.
$form_state->setErrorByName("domain][{$langcode}", $this->t('The domain for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value)));
}
}
// Domain names should not contain protocol and/or ports.
foreach ($languages as $langcode => $name) {
$value = $form_state->getValue(array('domain', $langcode));
if (!empty($value)) {
// Ensure we have exactly one protocol when checking the hostname.
$host = 'http://' . str_replace(array('http://', 'https://'), '', $value);
if (parse_url($host, PHP_URL_HOST) != $value) {
$form_state->setErrorByName("domain][{$langcode}", $this->t('The domain for %language may only contain the domain name, not a protocol and/or port.', array('%language' => $name)));
}
}
}
parent::validateForm($form, $form_state);
}
示例12: simplemap_exclusions_form
function simplemap_exclusions_form()
{
$create_rows = function () {
$loader = new ExcludedNodesLoader();
$excluded = $loader->loadExcludedNodes();
$available_langs = language_list();
return array_map(function ($node) use($available_langs) {
// The link must be created in the original node language, not in the
// current user language.
$node_link = l($node->title, "node/{$node->nid}", ['language' => $available_langs[$node->language]]);
$delete_link = l(t('Delete from Exclusion'), "admin/settings/simplemap/exclusions/{$node->nid}/delete");
return [$node->nid, $node_link, $delete_link];
}, $excluded);
};
return ['new_exclusion' => ['#type' => 'fieldset', '#title' => t('Add a new node to the exclusion list'), 'nid' => ['#type' => 'textfield', '#title' => t('NID'), '#required' => true], 'submit' => ['#type' => 'submit', '#value' => t('Add to the Exclusion List')]], 'existing_exclusions' => ['#type' => 'fieldset', '#title' => t('Nodes Excluded from Sitemaps'), 'list' => ['#theme' => 'table', '#header' => [t('NID'), t('Title'), ''], '#rows' => $create_rows()]]];
}
示例13: renderLink
/**
* {@inheritdoc}
*/
protected function renderLink($data, ResultRow $values)
{
if (!empty($this->options['link_to_user'])) {
$uid = $this->getValue($values, 'uid');
if ($this->view->getUser()->hasPermission('access user profiles') && $uid) {
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['path'] = 'user/' . $uid;
}
}
if (empty($data)) {
$lang = language_default();
} else {
$lang = language_list();
$lang = $lang[$data];
}
return $this->sanitizeValue($lang->getName());
}
示例14: alterItems
public function alterItems(array &$items)
{
// Prevent session information from being saved while indexing.
drupal_save_session(FALSE);
// Force the current user to anonymous to prevent access bypass in search
// indexes.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
$entity_type = $this->index->getEntityType();
$entity_handler = panelizer_entity_plugin_get_handler($entity_type);
foreach ($items as &$item) {
$entity_id = entity_id($entity_type, $item);
$item->search_api_panelizer_content = NULL;
$item->search_api_panelizer_title = NULL;
// If Search API specifies a language to view the item in, force the
// global language_content to be Search API item language. Fieldable
// panel panes will render in the correct language.
if (isset($item->search_api_language)) {
global $language_content;
$original_language_content = $language_content;
$languages = language_list();
if (isset($languages[$item->search_api_language])) {
$language_content = $languages[$item->search_api_language];
} else {
$language_content = language_default();
}
}
try {
if ($render_info = $entity_handler->render_entity($item, 'page_manager')) {
$item->search_api_panelizer_content = $render_info['content'];
$item->search_api_panelizer_title = !empty($render_info['title']) ? $render_info['title'] : NULL;
}
} catch (Exception $e) {
watchdog_exception('panelizer', $e, 'Error indexing Panelizer content for %entity_type with ID %entity_id', array('%entity_type' => $entity_type, '%entity_id' => $entity_id));
}
// Restore the language_content global if it was overridden.
if (isset($original_language_content)) {
$language_content = $original_language_content;
}
}
// Restore the user.
$GLOBALS['user'] = $original_user;
drupal_save_session(TRUE);
}
示例15: deliver
public function deliver(array $output = array())
{
$plugin = $this->plugin;
$message = $this->message;
$options = $plugin['options'];
$account = user_load($message->uid);
$mail = $options['mail'] ? $options['mail'] : $account->mail;
$languages = language_list();
if (!$options['language override']) {
$lang = !empty($account->language) && $account->language != LANGUAGE_NONE ? $languages[$account->language] : language_default();
} else {
$lang = $languages[$message->language];
}
// The subject in an email can't be with HTML, so strip it.
$output['message_notify_email_subject'] = strip_tags($output['message_notify_email_subject']);
// Pass the message entity along to hook_drupal_mail().
$output['message_entity'] = $message;
return drupal_mail('message_notify', $message->type, $mail, $lang, $output);
}