diff --git a/core/modules/locale/src/LocaleLookup.php b/core/modules/locale/src/LocaleLookup.php
index f5b4fc1..d46ae4b 100644
--- a/core/modules/locale/src/LocaleLookup.php
+++ b/core/modules/locale/src/LocaleLookup.php
@@ -117,7 +117,7 @@ protected function getCid() {
       // for example, strings for admin menu items and settings forms are not
       // cached for anonymous users.
       $user = \Drupal::currentUser();
-      $rids = $user ? implode(':', array_keys($user->getRoles())) : '0';
+      $rids = $user ? implode(':', $user->getRoles()) : '';
       $this->cid = "locale:{$this->langcode}:{$this->context}:$rids";
 
       // Getting the roles from the current user might have resulted in t()
diff --git a/core/modules/locale/tests/src/Unit/LocaleLookupTest.php b/core/modules/locale/tests/src/Unit/LocaleLookupTest.php
index fafcb45..a650840 100644
--- a/core/modules/locale/tests/src/Unit/LocaleLookupTest.php
+++ b/core/modules/locale/tests/src/Unit/LocaleLookupTest.php
@@ -111,7 +111,7 @@ public function testResolveCacheMissWithoutFallback() {
 
     $this->cache->expects($this->once())
       ->method('get')
-      ->with('locale:en:irrelevant:0', FALSE);
+      ->with('locale:en:irrelevant:anonymous', FALSE);
 
     $this->storage->expects($this->once())
       ->method('findTranslation')
@@ -183,7 +183,7 @@ public function testResolveCacheMissWithFallback($langcode, $string, $context, $
 
     $this->cache->expects($this->once())
       ->method('get')
-      ->with('locale:' . $langcode . ':' . $context . ':0', FALSE);
+      ->with('locale:' . $langcode . ':' . $context . ':anonymous', FALSE);
 
     $locale_lookup = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
     $this->assertSame($expected, $locale_lookup->get($string));
