From 2b4e547e15d47e59d63e497c46dc2b3c9a705ed3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tadej=20Ba=C5=A1a?= <tadej.basa@gmail.com>
Date: Mon, 14 Sep 2015 18:37:19 +0200
Subject: [PATCH] Patch for: https://www.drupal.org/node/1810178 - extra_field
 labels not translated.

---
 modules/field/field.info.class.inc | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/modules/field/field.info.class.inc b/modules/field/field.info.class.inc
index f4f1f63..212a3c5 100644
--- a/modules/field/field.info.class.inc
+++ b/modules/field/field.info.class.inc
@@ -449,13 +449,19 @@ class FieldInfo {
    *   The array of extra fields.
    */
   public function getBundleExtraFields($entity_type, $bundle) {
+    global $language;
+
     // Read from the "static" cache.
     if (isset($this->bundleExtraFields[$entity_type][$bundle])) {
       return $this->bundleExtraFields[$entity_type][$bundle];
     }
 
+    // The field_extra_fields() hook invoked below includes translated strings, so each
+    // language is cached separately.
+    $langcode = $language->language;
+
     // Read from the persistent cache.
-    if ($cached = cache_get("field_info:bundle_extra:$entity_type:$bundle", 'cache_field')) {
+    if ($cached = cache_get("field_info:bundle_extra:$entity_type:$bundle:$langcode", 'cache_field')) {
       $this->bundleExtraFields[$entity_type][$bundle] = $cached->data;
       return $this->bundleExtraFields[$entity_type][$bundle];
     }
@@ -473,9 +479,9 @@ class FieldInfo {
 
     // Store in the 'static' and persistent caches.
     $this->bundleExtraFields[$entity_type][$bundle] = $info;
-    if (lock_acquire("field_info:bundle_extra:$entity_type:$bundle")) {
-      cache_set("field_info:bundle_extra:$entity_type:$bundle", $info, 'cache_field');
-      lock_release("field_info:bundle_extra:$entity_type:$bundle");
+    if (lock_acquire("field_info:bundle_extra:$entity_type:$bundle:$langcode")) {
+      cache_set("field_info:bundle_extra:$entity_type:$bundle:$langcode", $info, 'cache_field');
+      lock_release("field_info:bundle_extra:$entity_type:$bundle:$langcode");
     }
 
     return $this->bundleExtraFields[$entity_type][$bundle];
-- 
2.1.4

