diff --git a/core/lib/Drupal/Core/Template/TwigNodeTrans.php b/core/lib/Drupal/Core/Template/TwigNodeTrans.php
index 29dea5a..ea51846 100644
--- a/core/lib/Drupal/Core/Template/TwigNodeTrans.php
+++ b/core/lib/Drupal/Core/Template/TwigNodeTrans.php
@@ -83,7 +83,7 @@ public function compile(\Twig_Compiler $compiler) {
     $compiler->raw(')');
 
     // Append translation debug markup, if necessary.
-    if (Settings::get('twig_debug', FALSE)) {
+    if ($compiler->getEnvironment()->isDebug()) {
       $compiler->raw(" . '\n<!-- TRANSLATION: ");
       $compiler->subcompile($singular);
       if (!empty($plural)) {
diff --git a/core/modules/system/src/Tests/Theme/TwigTransTest.php b/core/modules/system/src/Tests/Theme/TwigTransTest.php
index 20beeb5..10adc3b 100644
--- a/core/modules/system/src/Tests/Theme/TwigTransTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigTransTest.php
@@ -162,13 +162,12 @@ public function testTwigTransTags() {
    * Test Twig "trans" debug markup.
    */
   public function testTwigTransDebug() {
-    // Enable twig debug and write to the test settings.php file.
-    $this->settingsSet('twig_debug', TRUE);
-    $settings['settings']['twig_debug'] = (object) array(
-      'value' => TRUE,
-      'required' => TRUE,
-    );
-    $this->writeSettings($settings);
+    // Enable debug, rebuild the service container, and clear all caches.
+    $parameters = $this->container->getParameter('twig.config');
+    $parameters['debug'] = TRUE;
+    $this->setContainerParameter('twig.config', $parameters);
+    $this->rebuildContainer();
+    $this->resetAll();
 
     // Get page for assertion testing.
     $this->drupalGet('twig-theme-test/trans', array('language' => \Drupal::languageManager()->getLanguage('xx')));
