Answers.Body: <p>This line:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>$current_criteria-&gt;fieldId = craft()-&gt;fields-&gt;getFieldByHandle('translations');
  </code></pre>
  
  <p>should probably have a <code>-&gt;id</code> at the end?</p>
  
  <pre class="lang-php prettyprint-override"><code>$current_criteria-&gt;fieldId = craft()-&gt;fields-&gt;getFieldByHandle('translations')-&gt;id;
  </code></pre>
  
  <p>But the whole code could probably be replaced with:</p>
  
  <pre class="lang-php prettyprint-override"><code>function get_dynamic_translations() {
      $translations = array();
  
      if (!craft()-&gt;request-&gt;isCpRequest()) {
  
          $i18n = craft()-&gt;globals-&gt;getSetByHandle('i18n');
  
          foreach ($i18n-&gt;getFieldValue('translations') as $current_block) {
              $translations[$current_block-&gt;content-&gt;key] = $current_block-&gt;content-&gt;value;
          }
      }
  
      return $translations;
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-02T06:50:34.110Z
Answers.Text: Implementing this function causes the following error: 
  
  -> Undefined property: Craft\GlobalSetModel::$translations
  
  Ideas on how to proceed?
Answers.UserDisplayName: Kristian S. Munkvold
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-02T11:29:38.767Z
Answers.Text: @KristianS.Munkvold my assumption was that there is a `translations` field handle on your `i18n` global set - is that right?
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-02T12:48:01.947Z
Answers.Text: In addition – The main problem here is that this code interferes with how  plugins are loaded. I am unable to extract data from Custom Fields. Do you know why?
Answers.UserDisplayName: Kristian S. Munkvold
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-07T09:31:18.533Z
Answers.Text: Updated code in main question to reflect this solution. Main problem is still not fixed.
Answers.UserDisplayName: Kristian S. Munkvold
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-08T12:44:00.850Z
Answers.Text: @KristianS.MunkvoldI just tested this locally and it worked as expected. So it’s probably something simple like a typo in one of your field handles.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-08T14:23:50.853Z
Answers.Text: – There's no typo and I got it working. Could you read through my question once more? 
  
  I'm still struggling with the fact that Fetching a Localized Global as a Static Translation Causes Error in How Plugins Load.
Answers.UserDisplayName: Kristian S. Munkvold
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-01T20:48:36.340Z
Answers.LastActivityDate: 2017-06-14T20:26:33.737Z
Answers.LastEditDate: 2017-06-14T20:26:33.737Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I've extended all my "translations/[locale_id].php" to refer to this  function which enables us to put all our translations under a global in the control-panel.</p>
  
  <p>However, when this is done – we lose data attached to our assets. We currently use a Focal Point plugin attached to our assets. It describes with a field how images are to be cropped. This particular plugin stops working when the line highlighted below is executed.</p>
  
  <pre><code>function get_dynamic_translations() {
      $translations = array();
  
      if (!craft()-&gt;request-&gt;isCpRequest()) {
          // the following line makes the plugin "FocalPointField" stop loading its data
          $i18n = craft()-&gt;globals-&gt;getSetByHandle('i18n');
  
          foreach ($i18n-&gt;getFieldValue('translations') as $current_block) {
              $translations[$current_block-&gt;content-&gt;key] = $current_block-&gt;content-&gt;value;
          }
      }
  
      return $translations;
  
  
  }
  </code></pre>
  
  <p>I would love for these two solutions to work together in perfect harmony – but I can't seem to figure out why this is not working. </p>
  
  <p>Do you have any idea how I can go forth?</p>
  
Tags: <templating><localization>
Title: Fetching a Localized Global as a Static Translation Causes Error in How Plugins Load
ThreadText: # Fetching a Localized Global as a Static Translation Causes Error in How Plugins Load
  
  (Asked by: username_0 on 2017-06-01)
  
  I've extended all my "translations/[locale\_id].php" to refer to this function which enables us to put all our translations under a global in the control-panel.
  
  However, when this is done – we lose data attached to our assets. We currently use a Focal Point plugin attached to our assets. It describes with a field how images are to be cropped. This particular plugin stops working when the line highlighted below is executed.
  
  ```
  function get_dynamic_translations() {
      $translations = array();
  
      if (!craft()->request->isCpRequest()) {
          // the following line makes the plugin "FocalPointField" stop loading its data
          $i18n = craft()->globals->getSetByHandle('i18n');
  
          foreach ($i18n->getFieldValue('translations') as $current_block) {
              $translations[$current_block->content->key] = $current_block->content->value;
          }
      }
  
      return $translations;
  
  }
  
  ```
  
  I would love for these two solutions to work together in perfect harmony – but I can't seem to figure out why this is not working.
  
  Do you have any idea how I can go forth?
  
  **Tags:** templating, localization
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-06-01. Score: 2
  
  This line:
  
  ```php
  $current_criteria->fieldId = craft()->fields->getFieldByHandle('translations');
  
  ```
  
  should probably have a `->id` at the end?
  
  ```php
  $current_criteria->fieldId = craft()->fields->getFieldByHandle('translations')->id;
  
  ```
  
  But the whole code could probably be replaced with:
  
  ```php
  function get_dynamic_translations() {
      $translations = array();
  
      if (!craft()->request->isCpRequest()) {
  
          $i18n = craft()->globals->getSetByHandle('i18n');
  
          foreach ($i18n->getFieldValue('translations') as $current_block) {
              $translations[$current_block->content->key] = $current_block->content->value;
          }
      }
  
      return $translations;
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Implementing this function causes the following error:   -> Undefined property: Craft\GlobalSetModel::$translations  Ideas on how to proceed?  
  > **username_1**: @username_0 my assumption was that there is a `translations` field handle on your `i18n` global set - is that right?  
  > **username_0**: In addition – The main problem here is that this code interferes with how  plugins are loaded. I am unable to extract data from Custom Fields. Do you know why?  
  > **username_0**: Updated code in main question to reflect this solution. Main problem is still not fixed.  
  > **username_1**: @KristianS.MunkvoldI just tested this locally and it worked as expected. So it’s probably something simple like a typo in one of your field handles.  
  > **username_0**: – There's no typo and I got it working. Could you read through my question once more?   I'm still struggling with the fact that Fetching a Localized Global as a Static Translation Causes Error in How Plugins Load.  
  
  ---
  
  