@TODO: rename to getLocalization();

@return Localization
@throws CmsException
544861
protected function getPageLocalization()
	{
		// FIXME: using requested locale would make more common sense with global/local switch
		if (isset($this->pageData)) {
			return $this->pageData;
		}

		$this->pageData = $this->getPageLocalizationByRequestKey('page_id');

		if (empty($this->pageData)) {
			$pageId = $this->getRequestParameter('page_id');
			throw new CmsException('sitemap.error.page_not_found', "Page data for page {$pageId} not found");
		}

		/**
		 * Set the system current locale if differs from 'locale' parameter received.
		 * This is done for BACK button to work after navigating to page with different language.
		 * NB! this change won't be saved in the current locale browser cookie storage.
		 */
		$expectedLocaleId = $this->pageData->getLocaleId();

		if ($this->getCurrentLocale()->getId() !== $expectedLocaleId) {
			$this->container->getLocaleManager()
					->setCurrent($expectedLocaleId);
		}
		
		return $this->pageData;
	}
905657
private Locale getWorkplaceLocale() {

        Locale result = OpenCms.getWorkplaceManager().getWorkplaceLocale(getCmsObject());
        if (result == null) {
            result = CmsLocaleManager.getDefaultLocale();
        }
        if (result == null) {
            result = Locale.getDefault();
        }
        return result;
    }
224280
private Locale getContentLocale(ListConfigurationBean bean) {

        CmsObject cms = A_CmsUI.getCmsObject();
        if (bean.getFolders().isEmpty()) {
            return OpenCms.getLocaleManager().getDefaultLocale(cms, "/");
        } else {
            return OpenCms.getLocaleManager().getDefaultLocale(
                cms,
                cms.getRequestContext().removeSiteRoot(m_currentConfig.getFolders().get(0)));
        }
    }
425115
public Map<String, CmsJspResourceWrapper> getLocaleResource() {

        if (m_localeResources != null) {
            return m_localeResources;
        }
        try {
            CmsLocaleGroup localeGroup = m_cms.getLocaleGroupService().readLocaleGroup(this);
            Map<Locale, CmsResource> resourcesByLocale = localeGroup.getResourcesByLocale();
            Map<String, CmsJspResourceWrapper> result = Maps.newHashMap();
            for (Map.Entry<Locale, CmsResource> entry : resourcesByLocale.entrySet()) {
                result.put(entry.getKey().toString(), CmsJspResourceWrapper.wrap(m_cms, entry.getValue()));
            }
            m_localeResources = result;
            return result;
        } catch (CmsException e) {
            return new HashMap<String, CmsJspResourceWrapper>();
        }
    }
1189292
private void loadLocalizationFromXmlBundle(Locale locale) {

        CmsXmlContentValueSequence messages = m_xmlBundle.getValueSequence("Message", locale);
        SortedProperties props = new SortedProperties();
        if (null != messages) {
            for (I_CmsXmlContentValue msg : messages.getValues()) {
                String msgpath = msg.getPath();
                props.put(
                    m_xmlBundle.getStringValue(m_cms, msgpath + "/Key", locale),
                    m_xmlBundle.getStringValue(m_cms, msgpath + "/Value", locale));
            }
        }
        m_localizations.put(locale, props);
    }
242104
public Map<String, String> getValues() throws CmsException {

        CmsFile file = m_cms.readFile(m_editResource);
        CmsXmlContent content = unmarshalXmlContent(file);
        Locale locale = m_cms.getRequestContext().getLocale();
        if (!content.hasLocale(locale)) {
            content.addLocale(m_cms, locale);
        }
        return getContentValues(content, locale);
    }
778357
public List<String> getUrlNamesForAllLocales(CmsUUID id) throws CmsException {

        return m_securityManager.readUrlNamesForAllLocales(m_context, id);
    }
703432
protected Locale ensureLocale(Locale locale) {

        // get the default locale for the resource
        List<Locale> locales = OpenCms.getLocaleManager().getDefaultLocales(getCms(), getParamResource());
        if (m_content != null) {
            if (!m_content.hasLocale(locale)) {
                try {

                    // to copy anything we need at least one locale
                    if ((m_content.getLocales().size() > 0)) {
                        // required locale not available, check if an existing default locale should be copied as "template"
                        try {
                            // a list of possible default locales has been set as property, try to find a match
                            m_content.copyLocale(locales, locale);

                        } catch (CmsException e) {
                            m_content.addLocale(getCms(), locale);
                        }

                    } else {
                        m_content.addLocale(getCms(), locale);
                    }

                    writeContent();
                } catch (CmsException e) {
                    LOG.error(e.getMessageContainer(), e);
                }
            }
            if (!m_content.hasLocale(locale)) {
                // value may have changed because of the copy operation
                locale = m_content.getLocales().get(0);
            }
        }
        return locale;
    }
307994
public function getLocale(): string
    {
        if (is_null($this->locale)) {
            $this->locale = \Locale::getDefault();
        }

        return $this->locale;
    }
187404
private Locale getLocale(CmsXmlContent content) {

        List<Locale> locales = content.getLocales();
        if (locales.contains(Locale.ENGLISH) || locales.isEmpty()) {
            return Locale.ENGLISH;
        }
        return locales.get(0);
    }
317396
public void save() throws CmsException {

        if (hasChanges()) {
            switch (m_bundleType) {
                case PROPERTY:
                    saveLocalization();
                    saveToPropertyVfsBundle();
                    break;

                case XML:
                    saveLocalization();
                    saveToXmlVfsBundle();

                    break;

                case DESCRIPTOR:
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            if (null != m_descFile) {
                saveToBundleDescriptor();
            }

            resetChanges();
        }

    }
841058
public function moveAction()
	{
		$this->isPostRequest();
		
		$localization = $this->getPageLocalization();

		$page = $localization->getMaster();
		
		$input = $this->getRequestInput();

		$this->lockNestedSet($page);

		try {
			if ($input->has('reference_id')) {
				$sibling = $this->getPageByRequestKey('reference_id');

				if ($sibling === null) {
					throw new CmsException(null, sprintf('Sibling page [%s] not found.', $input->get('reference_id')));
				}

				if ($input->get('reference_type', 'before') === 'after') {
					$page->moveAsNextSiblingOf($sibling);
				} else {
					$page->moveAsPrevSiblingOf($sibling);
				}
				
			} elseif ($input->has('parent_id')) {

				$parent = $this->getPageByRequestKey('parent_id');

				if ($parent === null) {
					throw new CmsException(null, sprintf('Parent page [%s] not found.', $input->get('parent_id')));
				}

				$parent->addChild($page);
			} else {
				throw new \RuntimeException('Move destination is unknown.');
			}

		} catch (DuplicatePagePathException $e) {
			throw new CmsException('sitemap.error.duplicate_path');
		}

		$this->unlockNestedSet($page);

		return new SupraJsonResponse();
	}
589893
public Locale getLocale()
            throws JspException
    {
        Locale loc = null;
        if (_language != null || _country != null) {
            // language is required
            if (_language == null) {
                String s = Bundle.getString("Tags_LocaleRequiresLanguage", new Object[]{_country});
                registerTagError(s, null);
                return super.getUserLocale();
            }

            if (_country == null)
                loc = new Locale(_language);
            else
                loc = new Locale(_language, _country);
        }
        else
            loc = super.getUserLocale();

        return loc;
    }
189687
private void initLocales() {

        if (!m_localeCache.isEmpty()) {
            return;
        }
        readLocale(m_primaryResource);
        for (CmsResource resource : m_secondaryResources) {
            readLocale(resource);
        }
        for (Map.Entry<CmsResource, Locale> entry : m_localeCache.entrySet()) {
            CmsResource key = entry.getKey();
            Locale value = entry.getValue();
            m_resourcesByLocale.put(value, key);
        }
        try {
            CmsProperty noTranslationProp = m_cms.readPropertyObject(
                m_primaryResource,
                CmsPropertyDefinition.PROPERTY_LOCALE_NOTRANSLATION,
                false);
            m_noTranslation = noTranslationProp.getValue();
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);

        }
    }
1235535
void ensureSingleLocale(CmsXmlContainerPage containerPage, CmsResource localeRes) throws CmsException {

        CmsObject cms = getCmsObject();
        Locale mainLocale = CmsLocaleManager.getMainLocale(cms, localeRes);
        OpenCms.getLocaleManager();
        Locale defaultLocale = CmsLocaleManager.getDefaultLocale();
        if (containerPage.hasLocale(mainLocale)) {
            removeAllLocalesExcept(containerPage, mainLocale);
            // remove other locales
        } else if (containerPage.hasLocale(defaultLocale)) {
            containerPage.copyLocale(defaultLocale, mainLocale);
            removeAllLocalesExcept(containerPage, mainLocale);
        } else if (containerPage.getLocales().size() > 0) {
            containerPage.copyLocale(containerPage.getLocales().get(0), mainLocale);
            removeAllLocalesExcept(containerPage, mainLocale);
        } else {
            containerPage.addLocale(cms, mainLocale);
        }
    }
719516
protected Locale getLocale(String destination, List<CmsProperty> properties) {

        String localeName = CmsProperty.get(CmsPropertyDefinition.PROPERTY_LOCALE, properties).getValue();

        if (localeName != null) {
            // locale was already set on the files properties
            return OpenCms.getLocaleManager().getAvailableLocales(localeName).get(0);
        }
        // locale not set in properties, read default locales
        return OpenCms.getLocaleManager().getDefaultLocales(m_cms, CmsResource.getParentFolder(destination)).get(0);
    }
633188
public function applyLocale()
    {
        $strataLocale = $this->getCurrentLocale();
        $app = Strata::app();

        if (!is_null($strataLocale)) {
            $message =  setlocale(LC_ALL, $strataLocale->getCode() .'.UTF-8') ?
                "Localized to : " . $strataLocale->getCode() . ".UTF-8" :
                "Locale function is not available on this platform, or the given " .
                "local does not exist in this environment. Attempted to set: " .
                $strataLocale->getCode() . ".UTF-8";

            $app->setConfig("runtime.setlocale", $message);
        }

        // Set in PHP
        if (function_exists('bindtextdomain')) {
            $bound = bindtextdomain($this->getTextdomain(), Strata::getLocalePath());
            $app->setConfig("runtime.bindtextdomain", "PHP text domain was bound to <info>$bound</info>");
        }

        if (function_exists('textdomain')) {
            $bound = textdomain($this->getTextdomain());
            $app->setConfig("runtime.textdomain", "PHP message domain was bound to <info>$bound</info>");
        }

        // Set in WP
        global $locale;
        $locale = $strataLocale->getCode();

        return load_theme_textdomain($this->getTextdomain(), Strata::getLocalePath());
    }