public function getLanguage()
    {
        if ($this->language)
            return $this->language;
        if ($this->defaultLanguage)
            return $this->defaultLanguage;
        $prefered = $this->getPreferredLanguage();
        if (in_array($prefered, $this->availableLanguages))
            return $prefered;
        return $this->availableLanguages[0]; // if nothing works return first language from the list
    }