<p>I assume this is in the context of an <a href="https://craftcms.com/docs/plugins/events-reference#entry-api-events" rel="nofollow">event</a>, in which case you've got access to the EntryModel.</p>

<p>If so, <code>$entryModel-&gt;locale</code> should be what you're looking for.</p>

CC BY-SA 3.0
2016-05-12T17:55:22.150Z
2016-05-12T17:55:22.150Z
Brad Bell
<p><a href="https://i.sstatic.net/n0VJG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/n0VJG.png" alt="enter image description here"></a></p>

<p>Is there an easier way to get the CP's currently selected locale? In my plugin I am currently using this method.</p>

<pre><code>public function getCurrentLocale() {
    $id = is_array($this-&gt;value) ? $this-&gt;value[0] : false;
    $segments = craft()-&gt;request-&gt;segments;
    $lastSegment = end($segments);
    $locales = craft()-&gt;elements-&gt;getEnabledLocalesForElement($id);

    if (in_array($lastSegment, $locales)) {
        return $lastSegment;
    }

    return null;
}
</code></pre>

CC BY-SA 3.0
2016-05-12T15:38:38.263Z
My current method doesn't work if my plugin's field type is being used in globals, because in globals the locale is located in a different segment position.
a-am
CC BY-SA 3.0
2016-05-12T16:49:43.183Z
Do you mean the locale that you're currently viewing the control panel in, or if you're viewing an entry, the locale that you're viewing the entry in?
Brad Bell
CC BY-SA 3.0
2016-05-12T16:51:25.810Z
The locale I am currently viewing the entry in.
a-am
<plugin-development><localization>
Get CP's current selected locale
# Get CP's current selected locale

(Asked by: username_0 on 2016-05-12)

Is there an easier way to get the CP's currently selected locale? In my plugin I am currently using this method.
public function getCurrentLocale() {
    $id = is_array($this->value) ? $this->value[0] : false;
    $segments = craft()->request->segments;
    $lastSegment = end($segments);
    $locales = craft()->elements->getEnabledLocalesForElement($id);

    if (in_array($lastSegment, $locales)) {
        return $lastSegment;
    }

    return null;
}

**Tags:** plugin-development, localization

> **Comments:**
> **username_0**: My current method doesn't work if my plugin's field type is being used in globals, because in globals the locale is located in a different segment position.  
> **username_1**: Do you mean the locale that you're currently viewing the control panel in, or if you're viewing an entry, the locale that you're viewing the entry in?  
> **username_0**: The locale I am currently viewing the entry in.  

---

## 1 answers

### Answer by username_1 on 2016-05-12. Score: 1 | Accepted answer

I assume this is in the context of an [event](https://craftcms.com/docs/plugins/events-reference#entry-api-events), in which case you've got access to the EntryModel.

If so, `$entryModel->locale` should be what you're looking for.


---

