Problem/Motivation

Its not possible to compare to TranslationWrapper objects, due the circular dependency between LanguageManager and TranslationManager. This patch removes circular dependency.

Proposed resolution

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Draft a change record for the API changes Instructions

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webflo created an issue. See original summary.

webflo’s picture

alexpott’s picture

Oh wow... I like this.

webflo’s picture

FileSize
4.79 KB
4.11 KB
+++ b/core/lib/Drupal/Core/Language/LanguageManager.php
@@ -57,19 +50,12 @@ public function __construct(LanguageDefault $default_language) {
   protected function t($string, array $args = array(), array $options = array()) {
-    return $this->translation ? $this->translation->translate($string, $args, $options) : SafeMarkup::format($string, $args);
+    return new TranslationWrapper($string, $args, $options);
   }

Removed ::t() altogether.

plach’s picture

"Oh wow... I like this." (cit)

Status: Needs review » Needs work

The last submitted patch, 4: 2571375-4.patch, failed testing.

stefan.r’s picture

This is great, it removes the recursion that was bothering us in the var_export() and equality checks :)

Xano’s picture

Status: Needs work » Needs review
FileSize
935 bytes
5.71 KB
chx’s picture

Status: Needs review » Reviewed & tested by the community

yay for less circular dependencies circular less for yay

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

This would be good to test.

The last submitted patch, 4: 2571375-4.patch, failed testing.

Gábor Hojtsy’s picture

Issue tags: +D8MI, +language-base, +sprint
mr.baileys’s picture

Assigned: Unassigned » mr.baileys

Working on tests.

webflo’s picture

FileSize
1.54 KB
mr.baileys’s picture

Let's see if this fails.

alexpott’s picture

Assigned: mr.baileys » alexpott

So this is a bit more complex - I think we need to decouple the LanguageManager and TranslationManager completely. Discussed with @mr.baileys - I'm going to give this a shot.

Status: Needs review » Needs work

The last submitted patch, 15: 2571375-15-comparing-translation-objects-test-only.patch, failed testing.

The last submitted patch, 15: 2571375-15-comparing-translation-objects-test-only.patch, failed testing.

alexpott’s picture

Priority: Normal » Major
Status: Needs work » Needs review
FileSize
25.99 KB

The patch attached completely decouples TranslationManager from LanguageManager as well. This makes comparing TranslationWrappers much lighter. As the only injected objects it has are the Translators.

In order to do this we have to move TranslationManager::getNumberOfPlurals() to a service provided by locale - which makes perfect sense since it has little meaning of locale is not installed.

No interdiff provided because this is a major rework of the existing patch in #8 and it includes the tests (though converted to a KernelTestBase) from #15.

alexpott’s picture

+++ b/core/includes/install.core.inc
@@ -346,11 +346,8 @@ function install_begin_request($class_loader, &$install_state) {
   $container
-    ->register('language_manager', 'Drupal\Core\Language\LanguageManager')
-    ->addArgument(new Reference('language.default'));
-  $container
     ->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
-    ->addArgument(new Reference('language_manager'));
+    ->addArgument(new Reference('language.default'));

This makes me happy. Less services required during very very early installer.

Gábor Hojtsy’s picture

I discussed this new approach with @alexpott, and it makes total sense architecturally AFAIS.

Status: Needs review » Needs work

The last submitted patch, 19: 2571375-17.patch, failed testing.

The last submitted patch, 19: 2571375-17.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
25.32 KB

Rerolled patch included an incorrect change in AccountForm that has since been changed in HEAD.

Status: Needs review » Needs work

The last submitted patch, 24: 2571375-24.patch, failed testing.

alexpott’s picture

Updated to use TranslatableString and fixed up installer tests.

The last submitted patch, 26: 2571375-25.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 26: 2571375-26.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
964 bytes
27.46 KB

Fixing more tests

Status: Needs review » Needs work

The last submitted patch, 29: 2571375-29.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
980 bytes
28.42 KB

Fixing tests.

dawehner’s picture

I really like the idea of decoupling!

  1. +++ b/core/modules/locale/locale.services.yml
    @@ -14,6 +14,9 @@ services:
    +  locale.plural.forumla:
    +    class: Drupal\locale\PluralFormula
    

    I'm pretty convinced that forumla is the much nicer name. Did you solved the forumla? ... What are the forumlas needed to calculate the field of some juice

  2. +++ b/core/tests/Drupal/KernelTests/Core/StringTranslation/TranslationStringTest.php
    @@ -0,0 +1,74 @@
    + */
    +class TranslationStringTest extends KernelTestBase {
    +
    

    I hand out beers for everyone doing that!

The last submitted patch, 19: 2571375-17.patch, failed testing.

alexpott’s picture

  1. Fixed
  2. I have my beer!
chx’s picture

Edit: nevermind.

alexpott’s picture

$success = $this->value === $other; from core/vendor/phpunit/phpunit/src/Framework/Constraint/IsIdentical.php

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you!

chx’s picture

Status: Reviewed & tested by the community » Needs work
+    // We also 2 plurals if there is no explicit information yet

Also? There's nothing before. And there's no verb.

+   * Loads the formulae and stores them on the object if not set.

+   * @return []

Stores on what object? And this doesn't return anything. "@return void" seems to be the way.

+   *   An array for formulas.

An array of formulae? Most of the patch uses the latin plural of formula (which I do not like but if you do I won't object too much) and let's be consistent. The "for" is almost surely wrong unless my English grammar is badly off. When I (emphasis on I) see an "array for formulae" I expect a by reference array which gets populated.

 // @todo

Sure, we can do a doxygen todo, I have no problems except one: catch said "naked" todos are useless and all of them should be accompanied by an issue. Please file one.

$this->formulae = $this->state->get('locale.translation.plurals', []);

locale.translation.formulae perhaps?

 difference services

different services.

The last submitted patch, 24: 2571375-24.patch, failed testing.

stefan.r’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs tests
FileSize
3.68 KB
28.39 KB

Addressed #38

Formulas might be better, but not too bothered as this is only used on protected variables/methods and not part of the API.

The last submitted patch, 26: 2571375-25.patch, failed testing.

The last submitted patch, 26: 2571375-26.patch, failed testing.

stefan.r’s picture

By the way drush HEAD currently fails on drush si - I believe this patch would fix that?

The last submitted patch, 29: 2571375-29.patch, failed testing.

chx’s picture

Yes, drush + HEAD fails https://github.com/drush-ops/drush/pull/1619 issue + crude fix but this is better. Apparently if (isset($input[$element['#name']]) && $input[$element['#name']] == $element['#value']) { and $input[$element['#name']] becomes t('Save and continue') and then it crashes. So this is a better fix.

The last submitted patch, 31: 2571375-31.patch, failed testing.

The last submitted patch, 34: 2571375-33.patch, failed testing.

stefan.r queued 40: 2571375-40.patch for re-testing.

alexpott’s picture

Assigned: alexpott » Unassigned
phenaproxima’s picture

YAY! This fixed the fatal error I was getting when running drush si:

Fatal error: Nesting level too deep - recursive dependency? in /Users/phen/Sites/drupal8/core/lib/Drupal/Core/Form/FormBuilder.php on line 1310

Applying this patch corrects the issue. Looking at the code which triggered the fatal, the problem (and solution) make perfect sense. +1 RTBC.

effulgentsia’s picture

I also get the same fatal from Drush as #43/#45/#50, and also fixed with this patch, so yay!

I want to review this a bit more thoroughly before committing myself, but no objection to another committer beating me to it.

  • effulgentsia committed a537a30 on 8.0.x
    Issue #2571375 by alexpott, webflo, stefan.r, Xano, mr.baileys: Remove...
effulgentsia’s picture

Title: Remove TranslationManager dependency from LanguageManager » [needs change record] Remove TranslationManager dependency from LanguageManager
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

This looks great, and because it fixes a fatal error when installing Drupal via Drush, I pushed it to 8.0.x without a change record. But I think we do need a change record for this, both explaining the general decoupling and specifically mentioning the methods removed from interfaces:

+++ b/core/lib/Drupal/Core/Language/LanguageManagerInterface.php
@@ -16,14 +16,6 @@
-  public function setTranslation(TranslationInterface $translation);
+++ b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php
@@ -102,16 +102,4 @@ public function translateString(TranslatableString $translated_string);
-   public function getNumberOfPlurals($langcode = NULL);
edurenye’s picture

Since this was commited I have some Exceptions in some modules like monitoring and simplenews, the exception says that the service added in this patch "locale.plural.formula" doesn't exist.
This is a problem in my modules or in the core due to this commit?

edurenye’s picture

This is the complete Exception:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException thrown while calling __toString on a Drupal\Core\StringTranslation\PluralTranslatableString object in /home/arla/public_html/d8/core/lib/Drupal/Component/DependencyInjection/Container.php on line 161: You have requested a non-existent service "locale.plural.formula".
trigger_error('Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException thrown while calling __toString on a Drupal\Core\StringTranslation\PluralTranslatableString object in /home/arla/public_html/d8/core/lib/Drupal/Component/DependencyInjection/Container.php on line 161: You have requested a non-existent service "locale.plural.formula".', 256)
Drupal\Core\StringTranslation\TranslatableString->__toString()
strtr('@method @url returned @status (@length).', Array)
Drupal\Component\Utility\SafeMarkup::placeholderFormat('@method @url returned @status (@length).', Array, 1)
Drupal\Component\Utility\SafeMarkup::format('@method @url returned @status (@length).', Array)
Drupal\simpletest\WebTestBase->curlExec(Array)
Drupal\simpletest\WebTestBase->drupalGet('cron/5YfS85PzSKeeqZLAULUzcmoG3iuU3heUpOKVQgRJNOf9ORTiHsObzDUEjbkrKFuuBP5ZOKILiw')
Drupal\simpletest\WebTestBase->cronRun()
Drupal\simplenews\Tests\SimplenewsAdministrationTest->testNewsletterIssuesOverview()
Drupal\simpletest\TestBase->run()
_simpletest_batch_operation(Array, '2', Array)
call_user_func_array('_simpletest_batch_operation', Array)
_batch_process()
_batch_do()
_batch_page(Object)
Drupal\system\Controller\BatchController->batchPage(Object)
call_user_func_array(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

This just hapens in local not in the testbot (I'm running it in PHP 5.6).

Berdir’s picture

I think the problem is in PluralTranslatableString::getPluralIndex(). That checks the existence of the function, and that function then calls out to that service. But if the parent site has locale enabled then that module is loaded and there is nothing you can do about that.

Sounds like we need to change that to a module exists?

alexpott’s picture

andypost’s picture

That needs follow-up

  1. +++ b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php
    @@ -70,12 +70,17 @@ protected function formatPluralTranslated($count, $translated, array $args = arr
    -   * See the
    -   * \Drupal\Core\StringTranslation\TranslationInterface::getNumberOfPlurals()
    +   * See the \Drupal\locale\PluralFormulaInterface::getNumberOfPlurals()
        * documentation for details.
    +   *
    +   * @see \Drupal\locale\PluralFormulaInterface::getNumberOfPlurals()
    

    duplicates each other

  2. +++ b/core/modules/locale/src/PluralFormula.php
    @@ -0,0 +1,116 @@
    +  protected $formulae;
    ...
    +  protected function loadFormulae() {
    +    if (!isset($this->formulae)) {
    

    formula(e)?
    suppose 'formulas'

Oleksiy’s picture

YesCT’s picture

Issue tags: +rc eligible

change records can and should still be able to be updated, and since that is why this issue is still open, adding a tag so we can find this.

YesCT’s picture

Issue summary: View changes

adding link to instructions on how to draft a change record to the issue summary remaining tasks section
https://drupal.org/contributor-tasks/draft-change-record

  • effulgentsia committed a537a30 on 8.1.x
    Issue #2571375 by alexpott, webflo, stefan.r, Xano, mr.baileys: Remove...
plach’s picture

Please, can we get a CR for this?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • effulgentsia committed a537a30 on 8.3.x
    Issue #2571375 by alexpott, webflo, stefan.r, Xano, mr.baileys: Remove...

  • effulgentsia committed a537a30 on 8.3.x
    Issue #2571375 by alexpott, webflo, stefan.r, Xano, mr.baileys: Remove...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vijaycs85’s picture

Title: [needs change record] Remove TranslationManager dependency from LanguageManager » Remove TranslationManager dependency from LanguageManager
Status: Needs work » Needs review
Issue tags: -Needs change record
Gábor Hojtsy’s picture

Status: Needs review » Needs work

@vijaycs85: this happened before 8.0.0, so the branch for 8.1.x was not correct. Also fixed a header problem: https://www.drupal.org/node/2801819/revisions/view/10067211/10070045

As @effulgentsia said though

I think we do need a change record for this, both explaining the general decoupling and specifically mentioning the methods removed from interfaces:

that is not covered in the change entry yet.

vijaycs85’s picture

Status: Needs work » Needs review

Thanks @Gábor Hojtsy for the review. I have updated the CR to reflect @effulgentsia comment.

Gábor Hojtsy’s picture

Version: 8.2.x-dev » 8.0.x-dev
Status: Needs review » Fixed

Reviewed, updated a bit. Looks all done now :) Moving back to the right version.

Gábor Hojtsy’s picture

Issue tags: -sprint

Also finally removing from the sprint.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.