<commit_before><?php
class Vps_Trl
{
    private $_modelWeb;
    private $_modelVps;
    private $_languages; //cache

    const SOURCE_VPS = 'vps';
    const SOURCE_WEB = 'web';
    const TRLCP = 'trlcp';
    const TRLP = 'trlp';
    const TRLC = 'trlc';
    const TRL = 'trl';

    const ERROR_INVALID_CHAR = 'invalidChar';
    const ERROR_INVALID_STRING = 'invalidString';
    const ERROR_WRONG_NR_OF_ARGUMENTS = 'wrongNrOfArguments';
    protected $_errorMessages = array(
        self::ERROR_INVALID_CHAR => 'Unallowed character inbetween two quotationmark blocks (e.g. "aa"."bb)"',
        self::ERROR_INVALID_STRING => 'String is not valid. Unallowed characters are used',
        self::ERROR_WRONG_NR_OF_ARGUMENTS => 'To few arguments.'
    );


    public function __construct($config = array())
    {
        if (isset($config['modelVps'])) $this->_modelVps = $config['modelVps'];
        else $this->_modelVps = new Vps_Trl_Model_Vps();
        if (isset($config['modelWeb'])) $this->_modelVps = $config['modelWeb'];
        else $this->_modelWeb = new Vps_Trl_Model_Web();
    }

    public function setModel($model, $type)
    {
        if ($type == 'vps') $this->_modelVps = $model;
        else $this->_modelWeb = $model;
    }

    public function getLanguages()
    {

        if (!isset($this->_languages)) {
            $config = Zend_Registry::get('config');
            if ($config->languages) {
                $this->_languages = array_values($config->languages->toArray());
            } else if ($config->webCodeLanguage) {
                $this->_languages = array($config->webCodeLanguage);
            }
            if (empty($this->_languages)) {
                throw new Vps_Exception('Neither config languages nor config webCodeLanguage set.');
            }
        }
        return $this->_languages;
    }

    public function setLanguages($languages) //notwendig zum testen
    {
        $this->_languages = $languages;
    }

    public function getTargetLanguage()
    {
        $config = Zend_Registry::get('config');
        if (!Zend_Registry::get('userModel') ||
            !Zend_Registry::get('userModel')->getAuthedUser() ||
            !isset(Zend_Registry::get('userModel')->getAuthedUser()->language) ||
            !Zend_Registry::get('userModel')->getAuthedUser()->language)
            {
                return $this->getWebCodeLanguage();
        } else {
            return Zend_Registry::get('userModel')->getAuthedUser()->language;
        }
    }

    public function getWebCodeLanguage()
    {
        $config = Zend_Registry::get('config');
        if (isset($this->_webCodeLanguage) && $this->_webCodeLanguage) {
            return $this->_webCodeLanguage;
        }
        if ($config->webCodeLanguage) {
            return $config->webCodeLanguage;
        }
    }

    private function _getModel($type)
    {
         return $type == self::SOURCE_WEB ? $this->_modelWeb : $this->_modelVps;
    }

    public function trl($string, $params, $source, $language = null)
    {
        return $this->trlc('', $string, $params, $source, $language);
    }
<commit_msg>Wenn Benutzer unbekannte Sprache eingestellt hat, Defaultsprache verwenden<commit_after><?php
class Vps_Trl
{
    private $_modelWeb;
    private $_modelVps;
    private $_languages; //cache

    const SOURCE_VPS = 'vps';
    const SOURCE_WEB = 'web';
    const TRLCP = 'trlcp';
    const TRLP = 'trlp';
    const TRLC = 'trlc';
    const TRL = 'trl';

    const ERROR_INVALID_CHAR = 'invalidChar';
    const ERROR_INVALID_STRING = 'invalidString';
    const ERROR_WRONG_NR_OF_ARGUMENTS = 'wrongNrOfArguments';
    protected $_errorMessages = array(
        self::ERROR_INVALID_CHAR => 'Unallowed character inbetween two quotationmark blocks (e.g. "aa"."bb)"',
        self::ERROR_INVALID_STRING => 'String is not valid. Unallowed characters are used',
        self::ERROR_WRONG_NR_OF_ARGUMENTS => 'To few arguments.'
    );


    public function __construct($config = array())
    {
        if (isset($config['modelVps'])) $this->_modelVps = $config['modelVps'];
        else $this->_modelVps = new Vps_Trl_Model_Vps();
        if (isset($config['modelWeb'])) $this->_modelVps = $config['modelWeb'];
        else $this->_modelWeb = new Vps_Trl_Model_Web();
    }

    public function setModel($model, $type)
    {
        if ($type == 'vps') $this->_modelVps = $model;
        else $this->_modelWeb = $model;
    }

    public function getLanguages()
    {

        if (!isset($this->_languages)) {
            $config = Zend_Registry::get('config');
            if ($config->languages) {
                $this->_languages = array_values($config->languages->toArray());
            } else if ($config->webCodeLanguage) {
                $this->_languages = array($config->webCodeLanguage);
            }
            if (empty($this->_languages)) {
                throw new Vps_Exception('Neither config languages nor config webCodeLanguage set.');
            }
        }
        return $this->_languages;
    }

    public function setLanguages($languages) //notwendig zum testen
    {
        $this->_languages = $languages;
    }

    public function getTargetLanguage()
    {
        $config = Zend_Registry::get('config');
        if (!Zend_Registry::get('userModel') ||
            !Zend_Registry::get('userModel')->getAuthedUser() ||
            !isset(Zend_Registry::get('userModel')->getAuthedUser()->language) ||
            !Zend_Registry::get('userModel')->getAuthedUser()->language ||
            !in_array(Zend_Registry::get('userModel')->getAuthedUser()->language, $this->getLanguages()))
        {
            return $this->getWebCodeLanguage();
        } else {
            return Zend_Registry::get('userModel')->getAuthedUser()->language;
        }
    }

    public function getWebCodeLanguage()
    {
        $config = Zend_Registry::get('config');
        if (isset($this->_webCodeLanguage) && $this->_webCodeLanguage) {
            return $this->_webCodeLanguage;
        }
        if ($config->webCodeLanguage) {
            return $config->webCodeLanguage;
        }
    }

    private function _getModel($type)
    {
         return $type == self::SOURCE_WEB ? $this->_modelWeb : $this->_modelVps;
    }

    public function trl($string, $params, $source, $language = null)
    {
        return $this->trlc('', $string, $params, $source, $language);
    }

{'fraction_non_alphanumeric': 0.14234431090994226, 'fraction_numerical': 0.0, 'mean_word_length': 2.645051194539249, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 78, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7604144', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1873, 'n_words': 371}