I’ve written a Drupal Console command that creates an enormous batch of HTML snippets. That is executed by rendering a view programmatically (as in this StackExchange reply)
Drupal Developer process
Now I’ve to create these snippets in a number of languages.
This works
If I name Drupal Developer view in my browser I can simply selected Drupal Developer language with Drupal Developer respective path prefix:
http://www.instance.com/de/path/to/Drupal Developer/view (german model)
http://www.instance.com/en/path/to/Drupal Developer/view (english model)
This doesn’t work
If I attempt to render Drupal Developer exact same view from a Drupal Console command I’m not in a position to set Drupal Developer goal language. Drupal Developer rendered HTML is at all times in Drupal Developer default language.
At first I assumed passing Drupal Developer langcode in Drupal Developer view() technique ought to suffice:
// Now render Drupal Developer node as HTML $viewBuilder = $this->entityTypeManager->getViewBuilder('node'); $construct = $viewBuilder->view($node, 'full', $langcode); $html = $this->renderer->renderPlain($construct);
Then I attempted setConfigOverrideLanguage():
$this->languageManager->setConfigOverrideLanguage($language); // … render Drupal Developer view right here … $this->languageManager->setConfigOverrideLanguage($originalLanguage);
However this didn’t work both. So it tried:
$this->configFactory->getEditable('system.web site')->set('langcode', $langcode)->save(); // … render Drupal Developer view right here … $this->configFactory->getEditable('system.web site')->set('langcode', $originalLangcode)->save();
However I didn’t succeed. I even tried utilizing a customized LanguageNegotiator, however I ran right into a deadly error as a consequence of Drupal Developer undeniable fact that Drupal Developer service ‘language_manager’ doesn’t implement Drupal Developer ConfigurableLanguageManagerInterface, so it’s lacking Drupal Developer setNegotiator() and getNegotiator() strategies.
As soon as once more I’m completely caught and I do not know what I’m lacking (probably only a tiny bit). How in Drupal Developer world is it potential to alter Drupal Developer language of my rendered HTML???
Edit 2017-01-05:
I’ve to confess I’m fairly determined atm. I even tried every thing I dominated out above once more. Guess what, it nonetheless doesn’t work. Any concepts? I’m so shure that I’m lacking solely a tiny piece. However I haven’t got any thought the place to seek for 🙁
Edit 2017-01-17:
Clearly Drupal Developer console command isn’t conscious of (elements of) Drupal Developer context, even when I set Drupal Developer language. Simply to get it executed I’m contemplating placing collectively a request object which I might then have been dealt with by Drupal Developer kernel. If this could transform too sophisticated I might nonetheless curl Drupal Developer respective pages, however I’ve a sense that there needs to be one other approach of doing this.
Edit 2017-03-14:
To start with there there must be a translation (even when Drupal Developer node information is by no means language particular). If you’d like Drupal Developer full context it’s a must to use Drupal Developer Kernel’s deal with
technique with a sub request.