<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>

CC BY-SA 3.0
2017-06-02T06:50:34.110Z
Implementing this function causes the following error: 

-> Undefined property: Craft\GlobalSetModel::$translations

Ideas on how to proceed?
Kristian S. Munkvold
CC BY-SA 3.0
2017-06-02T11:29:38.767Z
@KristianS.Munkvold my assumption was that there is a `translations` field handle on your `i18n` global set - is that right?
Brandon Kelly
CC BY-SA 3.0
2017-06-02T12:48:01.947Z
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?
Kristian S. Munkvold
CC BY-SA 3.0
2017-06-07T09:31:18.533Z
Updated code in main question to reflect this solution. Main problem is still not fixed.
Kristian S. Munkvold
CC BY-SA 3.0
2017-06-08T12:44:00.850Z
@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.
Brandon Kelly
CC BY-SA 3.0
2017-06-08T14:23:50.853Z
– 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.
Kristian S. Munkvold
CC BY-SA 3.0
2017-06-01T20:48:36.340Z
2017-06-14T20:26:33.737Z
2017-06-14T20:26:33.737Z
Brandon Kelly
<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>

<templating><localization>
Fetching a Localized Global as a Static Translation Causes Error in How Plugins Load
# 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:
$current_criteria->fieldId = craft()->fields->getFieldByHandle('translations');

should probably have a ->id at the end?
$current_criteria->fieldId = craft()->fields->getFieldByHandle('translations')->id;

But the whole code could probably be replaced with:
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**: @KristianS.Munkvold 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.  

---

