diff --git a/core/includes/update.inc b/core/includes/update.inc index 90f30516176ee9d7c2dc27b9b84814f8ce965fea..1416fe088be20c1fb6f1f6fc501761b70ee281e6 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -744,9 +744,9 @@ function update_language_list($flags = LanguageInterface::STATE_CONFIGURABLE) { // Add the site's default language if flagged as allowed value. if ($flags & LanguageInterface::STATE_SITE_DEFAULT) { - $default = isset($default) ? $default : \Drupal::languageManager()->getDefaultLanguage(); + $default = \Drupal::languageManager()->getDefaultLanguage(); // Rename the default language. - $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); + $default->setName(t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()))); $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default; } diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index 175f9fb9528ad0dd57c1339c86276a68c74364ce..ec3ce713f08a0e8179aa3e387457b0df60952ddb 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -34,7 +34,7 @@ class Language implements LanguageInterface { * * @var string */ - public $name = ''; + protected $name = ''; /** * The ID, langcode. @@ -103,6 +103,15 @@ public function getName() { return $this->name; } + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->name = $name; + + return $this; + } + /** * {@inheritdoc} */ diff --git a/core/lib/Drupal/Core/Language/LanguageInterface.php b/core/lib/Drupal/Core/Language/LanguageInterface.php index c3e39a7137d95b8364cc13d9a971778841aaa18e..f230cf2b82cb6b77c931af85ba4b54895e60cc46 100644 --- a/core/lib/Drupal/Core/Language/LanguageInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageInterface.php @@ -109,6 +109,16 @@ interface LanguageInterface { */ public function getName(); + /** + * Sets the name of the language. + * + * @param string $name + * The human-readable English name of the language. + * + * @return $this + */ + public function setName($name); + /** * Gets the ID (language code). * diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 557faad6933d253751bf0c733f7726f73ff64acc..e0916e47b2ab338b223cd3ae679b257af0f83265 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -146,11 +146,9 @@ public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE) { // Add the site's default language if flagged as allowed value. if ($flags & LanguageInterface::STATE_SITE_DEFAULT) { - $default = isset($default) ? $default : $this->getDefaultLanguage(); - // Rename the default language. But we do not want to do this globally, - // if we're acting on a global object, so clone the object first. - $default = clone $default; - $default->name = $this->t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); + // Setup a language to have the defaults, but with overridden name. + $default = $this->getDefaultLanguage(); + $default->setName($this->t("Site's default language (@lang_name)", array('@lang_name' => $default->getName()))); $filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default; } @@ -187,7 +185,7 @@ public function getLanguageName($langcode) { return $this->t('None'); } if ($language = $this->getLanguage($langcode)) { - return $language->name; + return $language->getName(); } if (empty($langcode)) { return $this->t('Unknown'); diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php index 61cdc73d35fe8f987524005691f27b3756a17ecc..aa25cc693ce1854a4edbd10836f5a399b6f1139d 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php @@ -77,7 +77,7 @@ public function setValue($value, $notify = TRUE) { */ public function getString() { $language = $this->getValue(); - return $language ? $language->name : ''; + return $language ? $language->getName() : ''; } /** diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php index 73c87c3c7f48dda5edccce5d9261b2417db852b0..72fe9cc2bd526462d7f586bd95fdb0d3a38e6a88 100644 --- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/src/Controller/ConfigTranslationController.php @@ -164,7 +164,7 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl // Prepare the language name and the operations depending on whether this // is the original language or not. if ($langcode == $original_langcode) { - $language_name = '' . $this->t('@language (original)', array('@language' => $language->name)) . ''; + $language_name = '' . $this->t('@language (original)', array('@language' => $language->getName())) . ''; // Check access for the path/route for editing, so we can decide to // include a link to edit or not. @@ -180,7 +180,7 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl } } else { - $language_name = $language->name; + $language_name = $language->getName(); $operations = array(); // If no translation exists for this language, link to add one. diff --git a/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php b/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php index 1930c3bf524d2a6833a71abc8d0e3d71ced681da..883574dfd0e28e6502c1480bab3780e5155fbc8a 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php @@ -29,7 +29,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $ $form = parent::buildForm($form, $form_state, $request, $plugin_id, $langcode); $form['#title'] = $this->t('Add @language translation for %label', array( '%label' => $this->mapper->getTitle(), - '@language' => $this->language->name, + '@language' => $this->language->getName(), )); return $form; } @@ -39,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $ */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - drupal_set_message($this->t('Successfully saved @language translation.', array('@language' => $this->language->name))); + drupal_set_message($this->t('Successfully saved @language translation.', array('@language' => $this->language->getName()))); } } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php b/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php index 217d219eee895493f4dfbe6defdfea0c577d2cb4..b7146a34c85f64ca9bbbe32463836dccfc6f9f46 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php @@ -89,7 +89,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the @language translation of %label?', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name)); + return $this->t('Are you sure you want to delete the @language translation of %label?', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->getName())); } /** @@ -145,7 +145,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $cache_backend->deleteAll(); } - drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->name))); + drupal_set_message($this->t('@language translation of %label was deleted', array('%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()))); $form_state->setRedirectUrl($this->getCancelUrl()); } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php b/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php index 91e479731b74d266aa86d69d9b9a9b1ead06865c..2c1fc3c2778ee7ab619c9e17a2e27660364bc1f1 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php @@ -29,7 +29,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $ $form = parent::buildForm($form, $form_state, $request, $plugin_id, $langcode); $form['#title'] = $this->t('Edit @language translation for %label', array( '%label' => $this->mapper->getTitle(), - '@language' => $this->language->name, + '@language' => $this->language->getName(), )); return $form; } @@ -39,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state, Request $ */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - drupal_set_message($this->t('Successfully updated @language translation.', array('@language' => $this->language->name))); + drupal_set_message($this->t('Successfully updated @language translation.', array('@language' => $this->language->getName()))); } } diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php index fefe5f8a5a963b4899d81f6415203a2db21aa62c..5e052937e4b443d4c23803b24f3915e707f2aad8 100644 --- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php +++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php @@ -316,7 +316,7 @@ protected function buildConfigForm(Element $schema, $config_data, $base_config_d '!label (!source_language)', array( '!label' => $this->t($definition['label']), - '!source_language' => $this->sourceLanguage->name, + '!source_language' => $this->sourceLanguage->getName(), ) ), '#type' => 'item', diff --git a/core/modules/config_translation/src/FormElement/DateFormat.php b/core/modules/config_translation/src/FormElement/DateFormat.php index 5b19e26d9f305c6285d79cea0db27e6ab9979f2c..c3478e6eee200c31d1e02192a47411e0c0cd694e 100644 --- a/core/modules/config_translation/src/FormElement/DateFormat.php +++ b/core/modules/config_translation/src/FormElement/DateFormat.php @@ -29,7 +29,7 @@ public function getFormElement(DataDefinitionInterface $definition, LanguageInte $format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $value))); return array( '#type' => 'textfield', - '#title' => $this->t($definition->getLabel()) . ' (' . $language->name . ')', + '#title' => $this->t($definition->getLabel()) . ' (' . $language->getName() . ')', '#description' => $description, '#default_value' => $value, '#attributes' => array('lang' => $language->getId()), diff --git a/core/modules/config_translation/src/FormElement/Textarea.php b/core/modules/config_translation/src/FormElement/Textarea.php index 05b18bb40a28b7ae629a3040e162a6e756ce0122..804301ca5a368f4807802e7983816d5ae7db50e3 100644 --- a/core/modules/config_translation/src/FormElement/Textarea.php +++ b/core/modules/config_translation/src/FormElement/Textarea.php @@ -29,7 +29,7 @@ public function getFormElement(DataDefinitionInterface $definition, LanguageInte return array( '#type' => 'textarea', '#default_value' => $value, - '#title' => $this->t($definition->getLabel()) . ' (' . $language->name . ')', + '#title' => $this->t($definition->getLabel()) . ' (' . $language->getName() . ')', '#rows' => $rows, '#attributes' => array('lang' => $language->getId()), ); diff --git a/core/modules/config_translation/src/FormElement/Textfield.php b/core/modules/config_translation/src/FormElement/Textfield.php index ccd7cc589f92550223e4a927b866fd65bdb203f1..c28ca8d43c5ffccdb0bf7de20d81acf6211b3187 100644 --- a/core/modules/config_translation/src/FormElement/Textfield.php +++ b/core/modules/config_translation/src/FormElement/Textfield.php @@ -24,7 +24,7 @@ public function getFormElement(DataDefinitionInterface $definition, LanguageInte return array( '#type' => 'textfield', '#default_value' => $value, - '#title' => $this->t($definition->getLabel()) . ' (' . $language->name . ')', + '#title' => $this->t($definition->getLabel()) . ' (' . $language->getName() . ')', '#attributes' => array('lang' => $language->getId()), ); } diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php index 690beeef6773228a34922a7b3d9e3b822de0f01e..c7dc0c0634ad1fa593b2c0fa99d4ca8e506fc16d 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationUiTest.php @@ -325,7 +325,7 @@ public function testContactConfigEntityTranslation() { // Test that delete links work and operations perform properly. foreach ($this->langcodes as $langcode) { - $replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => language_load($langcode)->name); + $replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => language_load($langcode)->getName()); $this->drupalGet("$translation_base_url/$langcode/delete"); $this->assertRaw(t('Are you sure you want to delete the @language translation of %label?', $replacements)); diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 7636150c05259397cb9a6985e1e852fa8bca1105..231dbc63f33482c0447405fd6581978d09b13f0d 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -269,7 +269,7 @@ function content_translation_form_language_content_settings_validate(array $form $values = $bundle_settings['settings']['language']; if (empty($values['language_show']) && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { - $locked_languages[] = $language->name; + $locked_languages[] = $language->getName(); } $form_state->setErrorByName($name, t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(', ', $locked_languages)))); } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 29653bdb87cbacccf47d857916ba6ac3f54fb7d5..ffa5d89b6601aa361c106e526be27be4513b3e7d 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -677,7 +677,7 @@ function content_translation_language_configuration_element_validate($element, F $values = $form_state->getValue($key); if (!$values['language_show'] && $values['content_translation'] && \Drupal::languageManager()->isLanguageLocked($values['langcode'])) { foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $language) { - $locked_languages[] = $language->name; + $locked_languages[] = $language->getName(); } // @todo Set the correct form element name as soon as the element parents // are correctly set. We should be using NestedArray::getValue() but for diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index 90aa1c32e9178a7df203d4313a1c0d7be8b70c81..6b19b9dea66ac16e9ca35239be879f27607e0c4a 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -109,7 +109,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En $title = $this->entityFormTitle($entity); // When editing the original values display just the entity label. if ($form_langcode != $entity_langcode) { - $t_args = array('%language' => $languages[$form_langcode]->name, '%title' => $entity->label()); + $t_args = array('%language' => $languages[$form_langcode]->getName(), '%title' => $entity->label()); $title = empty($source_langcode) ? $title . ' [' . t('%language translation', $t_args) . ']' : t('Create %language translation of %title', $t_args); } $form['#title'] = $title; @@ -120,7 +120,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En if ($has_translations && $new_translation) { $form['source_langcode'] = array( '#type' => 'details', - '#title' => t('Source language: @language', array('@language' => $languages[$source_langcode]->name)), + '#title' => t('Source language: @language', array('@language' => $languages[$source_langcode]->getName())), '#tree' => TRUE, '#weight' => -100, '#multilingual' => TRUE, @@ -139,7 +139,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En ); foreach (language_list(LanguageInterface::STATE_CONFIGURABLE) as $language) { if (isset($translations[$language->getId()])) { - $form['source_langcode']['source']['#options'][$language->getId()] = $language->name; + $form['source_langcode']['source']['#options'][$language->getId()] = $language->getName(); } } } @@ -152,7 +152,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En $form['langcode']['#options'] = array(); foreach (language_list(LanguageInterface::STATE_CONFIGURABLE) as $language) { if (empty($translations[$language->getId()]) || $language->getId() == $entity_langcode) { - $form['langcode']['#options'][$language->getId()] = $language->name; + $form['langcode']['#options'][$language->getId()] = $language->getName(); } } } @@ -450,7 +450,7 @@ public function entityFormSourceChange($form, FormStateInterface $form_state) { 'target' => $form_object->getFormLangcode($form_state), )); $languages = language_list(); - drupal_set_message(t('Source language set to: %language', array('%language' => $languages[$source]->name))); + drupal_set_message(t('Source language set to: %language', array('%language' => $languages[$source]->getName()))); } /** diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index 999a509fc0c46989b0d226220d8a30a8f405cd37..e3622dc9ddf3249a1e043f0be7cdacbef12803ba 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -75,7 +75,7 @@ public function overview(Request $request, $entity_type_id = NULL) { $show_source_column = !empty($additional_source_langcodes); foreach ($languages as $language) { - $language_name = $language->name; + $language_name = $language->getName(); $langcode = $language->getId(); $add_url = new Url( @@ -161,7 +161,7 @@ public function overview(Request $request, $entity_type_id = NULL) { $source_name = $this->t('n/a'); } else { - $source_name = isset($languages[$source]) ? $languages[$source]->name : $this->t('n/a'); + $source_name = isset($languages[$source]) ? $languages[$source]->getName() : $this->t('n/a'); if ($handler->getTranslationAccess($entity, 'delete')->isAllowed()) { $links['delete'] = array( 'title' => $this->t('Delete'), diff --git a/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php b/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php index 9812a1a029beebe99d0ffa6ed49e113400166d92..b6b16e62bfd920fb14978180625227832298c607 100644 --- a/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php +++ b/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php @@ -57,7 +57,7 @@ public function getConfirmText() { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->name, '%label' => $this->entity->label())); + return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->getName(), '%label' => $this->entity->label())); } /** diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 55b99201cf85ea025c9b85527ac8eb555f654c95..a6053607d0a449963d562119e55d995574e9f8f4 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -149,7 +149,7 @@ function language_process_language_select($element) { if (!isset($element['#options'])) { $element['#options'] = array(); foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) { - $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; + $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } } // Add "Built-in English" language to the select when the default value is @@ -490,7 +490,7 @@ function language_form_system_regional_settings_alter(&$form, FormStateInterface $languages = \Drupal::languageManager()->getLanguages(); $default = \Drupal::languageManager()->getDefaultLanguage(); foreach ($languages as $key => $language) { - $language_options[$key] = $language->name; + $language_options[$key] = $language->getName(); } $form['locale']['site_default_language'] = array( '#type' => 'select', diff --git a/core/modules/language/src/Element/LanguageConfiguration.php b/core/modules/language/src/Element/LanguageConfiguration.php index 8204a787be1d8f7a548a201f8dbfa164cc6afb53..5ae8b002217066c3298bc7b363a8acdf0e38f234 100644 --- a/core/modules/language/src/Element/LanguageConfiguration.php +++ b/core/modules/language/src/Element/LanguageConfiguration.php @@ -92,14 +92,14 @@ public static function processLanguageConfiguration(&$element, FormStateInterfac */ protected static function getDefaultOptions() { $language_options = array( - LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (!language)", array('!language' => static::languageManager()->getDefaultLanguage()->name)), + LanguageInterface::LANGCODE_SITE_DEFAULT => t("Site's default language (!language)", array('!language' => static::languageManager()->getDefaultLanguage()->getName())), 'current_interface' => t('Current interface language'), 'authors_default' => t("Author's preferred language"), ); $languages = static::languageManager()->getLanguages(LanguageInterface::STATE_ALL); foreach ($languages as $langcode => $language) { - $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; + $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } return $language_options; diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index 668a9aa781931e17dadb02d05b96655e7be6685b..5ae24a79f864f11b2a419e6bedc4843521c5edd9 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -200,6 +200,15 @@ public function getName() { return $this->label(); } + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->label = $name; + + return $this; + } + /** * {@inheritdoc} */ diff --git a/core/modules/language/src/Form/LanguageAddForm.php b/core/modules/language/src/Form/LanguageAddForm.php index 8561acb043d6d632cf4e48382537492f33717bc7..93f14452d08659d034da8f56b562cc102ca9d2bc 100644 --- a/core/modules/language/src/Form/LanguageAddForm.php +++ b/core/modules/language/src/Form/LanguageAddForm.php @@ -118,7 +118,7 @@ public function validateCustom(array $form, FormStateInterface $form_state) { $this->validateCommon($form['custom_language'], $form_state); if ($language = language_load($langcode)) { - $form_state->setErrorByName('langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); + $form_state->setErrorByName('langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode))); } } else { @@ -136,7 +136,7 @@ public function validatePredefined($form, FormStateInterface $form_state) { } else { if ($language = language_load($langcode)) { - $form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->name, '%langcode' => $langcode))); + $form_state->setErrorByName('predefined_langcode', $this->t('The language %language (%langcode) already exists.', array('%language' => $language->getName(), '%langcode' => $langcode))); } } } diff --git a/core/modules/language/src/Form/NegotiationBrowserForm.php b/core/modules/language/src/Form/NegotiationBrowserForm.php index 766ecb53e760865fe28a41b0b61ad3f78303486e..aea7ad19d9f03e853e0db7cc0fda1b6d13ba7ea8 100644 --- a/core/modules/language/src/Form/NegotiationBrowserForm.php +++ b/core/modules/language/src/Form/NegotiationBrowserForm.php @@ -64,7 +64,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $existing_languages = array(); foreach ($languages as $langcode => $language) { - $existing_languages[$langcode] = $language->name; + $existing_languages[$langcode] = $language->getName(); } // If we have no languages available, present the list of predefined languages diff --git a/core/modules/language/src/Form/NegotiationUrlForm.php b/core/modules/language/src/Form/NegotiationUrlForm.php index 0b3735f90f649241ce8d39a9ad995a49c63e08f4..dcb721aa1389606c9e18e5c27fd93a3f597d185b 100644 --- a/core/modules/language/src/Form/NegotiationUrlForm.php +++ b/core/modules/language/src/Form/NegotiationUrlForm.php @@ -73,7 +73,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $prefixes = language_negotiation_url_prefixes(); $domains = language_negotiation_url_domains(); foreach ($languages as $langcode => $language) { - $t_args = array('%language' => $language->name, '%langcode' => $language->getId()); + $t_args = array('%language' => $language->getName(), '%langcode' => $language->getId()); $form['prefix'][$langcode] = array( '#type' => 'textfield', '#title' => $language->isDefault() ? $this->t('%language (%langcode) path prefix (Default language)', $t_args) : $this->t('%language (%langcode) path prefix', $t_args), @@ -83,7 +83,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ); $form['domain'][$langcode] = array( '#type' => 'textfield', - '#title' => $this->t('%language (%langcode) domain', array('%language' => $language->name, '%langcode' => $language->getId())), + '#title' => $this->t('%language (%langcode) domain', array('%language' => $language->getName(), '%langcode' => $language->getId())), '#maxlength' => 128, '#default_value' => isset($domains[$langcode]) ? $domains[$langcode] : '', ); @@ -120,7 +120,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { 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))); + $form_state->setErrorByName("prefix][$langcode", $this->t('The prefix for %language, %value, is not unique.', array('%language' => $language->getName(), '%value' => $value))); } } @@ -133,13 +133,13 @@ public function validateForm(array &$form, FormStateInterface $form_state) { 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))); + $form_state->setErrorByName("domain][$langcode", $this->t('The domain may not be left blank for %language.', array('%language' => $language->getName()))); } } 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))); + $form_state->setErrorByName("domain][$langcode", $this->t('The domain for %language, %value, is not unique.', array('%language' => $language->getName(), '%value' => $value))); } } diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php index 07095e17b661ca73d603d657edebd23b0591a679..0f46dd5d2459076dd47b980e038cc92a2511b356 100644 --- a/core/modules/language/src/Plugin/Condition/Language.php +++ b/core/modules/language/src/Plugin/Condition/Language.php @@ -72,7 +72,7 @@ public function summary() { // 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; + $result[$item->getId()] = $item->getName(); } return $result; }, array()); diff --git a/core/modules/language/src/Tests/LanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageConfigurationTest.php index 61edf4ebf33158f6f0e80801bf103521fd223264..32f70e67984c92b15b0a822f7fed6b4e7424ae31 100644 --- a/core/modules/language/src/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageConfigurationTest.php @@ -156,7 +156,7 @@ protected function checkConfigurableLanguageWeight($state = 'by default') { $max_configurable_language_weight = $this->getHighestConfigurableLanguageWeight(); $replacements = array('@event' => $state); foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_LOCKED) as $locked_language) { - $replacements['%language'] = $locked_language->name; + $replacements['%language'] = $locked_language->getName(); $this->assertTrue($locked_language->getWeight() > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements)); } } diff --git a/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php index c38d93ea66ad947f14f4b7631c84314a1c87166f..9ec78f4c14876c6efe7d3c4e0fe26704db1a0ce9 100644 --- a/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/src/Tests/LanguageUILanguageNegotiationTest.php @@ -380,7 +380,7 @@ function testUrlLanguageFallback() { // language. $args = array(':id' => 'block-test-language-block', ':url' => base_path() . $GLOBALS['script_path'] . $langcode_browser_fallback); $fields = $this->xpath('//div[@id=:id]//a[@class="language-link active" and starts-with(@href, :url)]', $args); - $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->name, 'The browser language is the URL active language'); + $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language'); // Check that URLs are rewritten using the given browser language. $fields = $this->xpath('//strong[@class="site-name"]/a[@rel="home" and @href=:url]', $args); diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index b9804d6e32850104af854402920d100cdf937a61..8aa8d82370f43ffab9deda34e98649c804fc6354 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -249,10 +249,10 @@ function locale_requirements($phase) { foreach ($status as $project) { foreach ($project as $langcode => $project_info) { if (empty($project_info->type)) { - $untranslated[$langcode] = $languages[$langcode]->name; + $untranslated[$langcode] = $languages[$langcode]->getName(); } elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) { - $available_updates[$langcode] = $languages[$langcode]->name; + $available_updates[$langcode] = $languages[$langcode]->getName(); } } } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 957dc8e2ed7f411fd94193fa162a73b2ae93d356..04dfb802a847fc0b12b60d63bd70f0aaf7a89016 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -1262,7 +1262,7 @@ function _locale_rebuild_js($langcode = NULL) { $logger = \Drupal::logger('locale'); switch ($status) { case 'updated': - $logger->notice('Updated JavaScript translation file for the language %language.', array('%language' => $language->name)); + $logger->notice('Updated JavaScript translation file for the language %language.', array('%language' => $language->getName())); return TRUE; case 'rebuilt': @@ -1271,15 +1271,15 @@ function _locale_rebuild_js($langcode = NULL) { // been created again. case 'created': - $logger->notice('Created JavaScript translation file for the language %language.', array('%language' => $language->name)); + $logger->notice('Created JavaScript translation file for the language %language.', array('%language' => $language->getName())); return TRUE; case 'deleted': - $logger->notice('Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->name)); + $logger->notice('Removed JavaScript translation file for the language %language because no translations currently exist for that language.', array('%language' => $language->getName())); return TRUE; case 'error': - $logger->error('An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->name)); + $logger->error('An error occurred during creation of the JavaScript translation file for the language %language.', array('%language' => $language->getName())); return FALSE; default: diff --git a/core/modules/locale/src/Form/ExportForm.php b/core/modules/locale/src/Form/ExportForm.php index 00a4be11026696e0166b7f252653f1a7c8bd6e9e..f9b6361f5a4ed5ac0b3db1b31e715acc460ae028 100644 --- a/core/modules/locale/src/Form/ExportForm.php +++ b/core/modules/locale/src/Form/ExportForm.php @@ -62,7 +62,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $language_options = array(); foreach ($languages as $langcode => $language) { if ($langcode != 'en' || locale_translate_english()) { - $language_options[$langcode] = $language->name; + $language_options[$langcode] = $language->getName(); } } $language_default = $this->languageManager->getDefaultLanguage(); @@ -143,7 +143,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $reader->setLangcode($language->getId()); $reader->setOptions($content_options); $languages = $this->languageManager->getLanguages(); - $language_name = isset($languages[$language->getId()]) ? $languages[$language->getId()]->name : ''; + $language_name = isset($languages[$language->getId()]) ? $languages[$language->getId()]->getName() : ''; $filename = $language->getId() .'.po'; } else { diff --git a/core/modules/locale/src/Form/ImportForm.php b/core/modules/locale/src/Form/ImportForm.php index eda1567a876fc7bb83bd1c1f9e5571f727c07df9..ae4424c88c818a3a0f52d092095b15c69c4e9bb7 100644 --- a/core/modules/locale/src/Form/ImportForm.php +++ b/core/modules/locale/src/Form/ImportForm.php @@ -80,7 +80,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $existing_languages = array(); foreach ($languages as $langcode => $language) { if ($langcode != 'en' || locale_translate_english()) { - $existing_languages[$langcode] = $language->name; + $existing_languages[$langcode] = $language->getName(); } } diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php index 131612f843e409f81726171df9e8519646853605..a14983c77d7d68d72fc140f3a0ce96d91079cf48 100644 --- a/core/modules/locale/src/Form/TranslateEditForm.php +++ b/core/modules/locale/src/Form/TranslateEditForm.php @@ -34,7 +34,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $this->languageManager->reset(); $languages = language_list(); - $langname = isset($langcode) ? $languages[$langcode]->name : "- None -"; + $langname = isset($langcode) ? $languages[$langcode]->getName() : "- None -"; $form['#attached']['library'][] = 'locale/drupal.locale.admin'; diff --git a/core/modules/locale/src/Form/TranslateFormBase.php b/core/modules/locale/src/Form/TranslateFormBase.php index 8ff3cd859d3c6ecfa28b3f90849c59c692053634..f2dbc824003ea4b15d2e79015dd6726b32427094 100644 --- a/core/modules/locale/src/Form/TranslateFormBase.php +++ b/core/modules/locale/src/Form/TranslateFormBase.php @@ -165,7 +165,7 @@ protected function translateFilters() { $language_options = array(); foreach ($languages as $langcode => $language) { if ($langcode != 'en' || locale_translate_english()) { - $language_options[$langcode] = $language->name; + $language_options[$langcode] = $language->getName(); } } diff --git a/core/modules/locale/src/Form/TranslationStatusForm.php b/core/modules/locale/src/Form/TranslationStatusForm.php index 2b20c47a952a041cc1046e93efc967931eccb6cf..3487589c21528348503e1442273e7ee8a6349537 100644 --- a/core/modules/locale/src/Form/TranslationStatusForm.php +++ b/core/modules/locale/src/Form/TranslationStatusForm.php @@ -82,7 +82,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Build data options for the select table. foreach ($updates as $langcode => $update) { - $title = String::checkPlain($languages[$langcode]->name); + $title = String::checkPlain($languages[$langcode]->getName()); $locale_translation_update_info = array('#theme' => 'locale_translation_update_info'); foreach (array('updates', 'not_found') as $update_status) { if (isset($update[$update_status])) { diff --git a/core/modules/node/src/NodeViewBuilder.php b/core/modules/node/src/NodeViewBuilder.php index 5f82472cdfc42b87493935cbf6b417612f6bf5a1..54f57b4001b61e92291deccf9d6efbef1266b770 100644 --- a/core/modules/node/src/NodeViewBuilder.php +++ b/core/modules/node/src/NodeViewBuilder.php @@ -58,7 +58,7 @@ public function buildComponents(array &$build, array $entities, array $displays, $build[$id]['langcode'] = array( '#type' => 'item', '#title' => t('Language'), - '#markup' => $entity->language()->name, + '#markup' => $entity->language()->getName(), '#prefix' => '
', '#suffix' => '
' ); diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index c5ad9909ce47a9e19b0ffe00275e7e17a3208fdb..ec0ac1507de430382ca35ab8faf62b943da24f59 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -446,7 +446,7 @@ public function searchFormAlter(array &$form, FormStateInterface $form_state) { $language_list = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_ALL); foreach ($language_list as $langcode => $language) { // Make locked languages appear special in the list. - $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; + $language_options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } if (count($language_options) > 1) { $form['advanced']['lang-fieldset'] = array( diff --git a/core/modules/node/src/Plugin/views/field/Language.php b/core/modules/node/src/Plugin/views/field/Language.php index 829973fbd0aaad1589d8909d27a0fe3118f011e6..9e55ce9f5c22535c0d993ff0774105181b843157 100644 --- a/core/modules/node/src/Plugin/views/field/Language.php +++ b/core/modules/node/src/Plugin/views/field/Language.php @@ -45,7 +45,7 @@ public function render(ResultRow $values) { // ready, see http://drupal.org/node/1616594. $value = $this->getValue($values); $language = language_load($value); - $value = $language ? $language->name : ''; + $value = $language ? $language->getName() : ''; return $this->renderLink($value, $values); } diff --git a/core/modules/path/src/Form/PathFormBase.php b/core/modules/path/src/Form/PathFormBase.php index f4d930957b6a110a602e235c00fa076f0f511734..bee68702f45c147b655acb2e2a8588cc04ec6a2f 100644 --- a/core/modules/path/src/Form/PathFormBase.php +++ b/core/modules/path/src/Form/PathFormBase.php @@ -114,7 +114,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $pid = NU $languages = \Drupal::languageManager()->getLanguages(); $language_options = array(); foreach ($languages as $langcode => $language) { - $language_options[$langcode] = $language->name; + $language_options[$langcode] = $language->getName(); } $form['langcode'] = array( diff --git a/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php index 3ec7fe8bfd9404c81ef1b460566b97ad164ff50e..1ebed3bead2836d3bbee38713b574c6a3c44f07d 100644 --- a/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php +++ b/core/modules/system/src/Tests/Form/LanguageSelectElementTest.php @@ -55,8 +55,10 @@ function testLanguageSelectElementOptions() { foreach ($ids as $id => $flags) { $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id))); $options = array(); - foreach ($this->container->get('language_manager')->getLanguages($flags) as $langcode => $language) { - $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->name)) : $language->name; + /* @var $language_manager \Drupal\Core\Language\LanguageManagerInterface */ + $language_manager = $this->container->get('language_manager'); + foreach ($language_manager->getLanguages($flags) as $langcode => $language) { + $options[$langcode] = $language->isLocked() ? t('- @name -', array('@name' => $language->getName())) : $language->getName(); } $this->_testLanguageSelectElementOptions($id, $options); } diff --git a/core/modules/taxonomy/src/Plugin/views/field/Language.php b/core/modules/taxonomy/src/Plugin/views/field/Language.php index f95f4929d3f5f28eeadf23fd092f79481d042e19..3fbc0b839542c72938d5a3ffc6af513ff176a539 100644 --- a/core/modules/taxonomy/src/Plugin/views/field/Language.php +++ b/core/modules/taxonomy/src/Plugin/views/field/Language.php @@ -22,7 +22,7 @@ class Language extends Taxonomy { public function render(ResultRow $values) { $value = $this->getValue($values); $language = \Drupal::languageManager()->getLanguage($value); - $value = $language ? $language->name : ''; + $value = $language ? $language->getName() : ''; return $this->renderLink($this->sanitizeValue($value), $values); } diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index 2edf4c321b83495077e59f9be7bd506a59883395..ccb86e3d0281c6279ad90906f61c9544ba494c92 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -422,7 +422,7 @@ protected function listLanguages($flags = LanguageInterface::STATE_ALL) { if ($id == LanguageInterface::LANGCODE_SITE_DEFAULT) { $id = PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT; } - $list[$id] = $this->t($language->name); + $list[$id] = $this->t($language->getName()); } // Add in negotiated languages, if requested. diff --git a/core/modules/views/src/Plugin/views/field/LanguageField.php b/core/modules/views/src/Plugin/views/field/LanguageField.php index 60b5a7cfbb83d1e71367b6a7d59c1b003d8810a3..5792bd002fdc34ae817efed03979f8f29466c594 100644 --- a/core/modules/views/src/Plugin/views/field/LanguageField.php +++ b/core/modules/views/src/Plugin/views/field/LanguageField.php @@ -44,7 +44,7 @@ public function render(ResultRow $values) { // ready, see http://drupal.org/node/1616594. $value = $this->getValue($values); $language = language_load($value); - return $language ? $language->name : ''; + return $language ? $language->getName() : ''; } } diff --git a/core/tests/Drupal/Tests/Core/Language/LanguageUnitTest.php b/core/tests/Drupal/Tests/Core/Language/LanguageUnitTest.php index e15cbac2bdf6ce9e6c9733834ce013059034bf37..e21ab6f12b84084cabc537096557b689cd4d04f7 100644 --- a/core/tests/Drupal/Tests/Core/Language/LanguageUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Language/LanguageUnitTest.php @@ -19,12 +19,15 @@ class LanguageUnitTest extends UnitTestCase { /** * @covers ::getName() + * @covers ::setName() */ public function testGetName() { $name = $this->randomMachineName(); $language_code = $this->randomMachineName(2); $language = new Language(array('id' => $language_code, 'name' => $name)); $this->assertSame($name, $language->getName()); + $new_name = $this->randomMachineName(); + $this->assertSame($new_name, $language->setName($new_name)->getName()); } /**