enter image description here

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;
  • 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. – aran May 12 '16 at 15:38
  • 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 May 12 '16 at 16:49
  • The locale I am currently viewing the entry in. – aran May 12 '16 at 16:51

I assume this is in the context of an event, in which case you've got access to the EntryModel.

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.