public function translate($string, $context = 'default', $language = 'default')
    {
        if ($this->isDefault($language)) {
            $language = $this->currentLanguage;
        } else {
            $this->setLanguage($language);
        }

        //get string from cache
        if (array_key_exists($context, $this->strings[$language]) &&
            array_key_exists($string, $this->strings[$language][$context])) {
            return $this->strings[$language][$context][$string];
        }

        //check in db
        $db_string = StringModel::select('id', 'date_creation')
            ->where('string', $string)
            ->where('context', $context)
            ->first();

        if (!$db_string) {
            $this->translateInsertString($context, $string);

            return $string;
        }

        $text = $this->translateGetString($context, $language, $db_string->id);
        if ($text) {
            $this->strings[$language][$context][$string] = $text;

            return $text;
        }

        return $string;
    }
public function translate($string, $context = 'default', $language = 'default')
    {
        if ($this->isDefault($language)) {
            $language = $this->currentLanguage;
        } else {
            $this->setLanguage($language);
        }

        //get string from cache
        if (array_key_exists($context, $this->strings[$language]) &&
            array_key_exists($string, $this->strings[$language][$context])) {
            return $this->strings[$language][$context][$string];
        }

        //check in db
        $db_string = StringModel::select('id', 'date_creation')
            ->where('string', $string)
            ->where('context', $context)
            ->first();

        if (!$db_string) {
            $this->translateInsertString($context, $string);

            return $string;
        }

        $text = $this->translateGetString($context, $language, $db_string->id);
        if ($text) {
            $this->strings[$language][$context][$string] = $text;

            return $text;
        }

        return $string;
    }
public function translate ( $ string , $ context = 'default' , $ language = 'default' ) { if ( $ this -> isDefault ( $ language ) ) { $ language = $ this -> currentLanguage ; } else { $ this -> setLanguage ( $ language ) ; } //get string from cache if ( array_key_exists ( $ context , $ this -> strings [ $ language ] ) && array_key_exists ( $ string , $ this -> strings [ $ language ] [ $ context ] ) ) { return $ this -> strings [ $ language ] [ $ context ] [ $ string ] ; } //check in db $ db_string = StringModel :: select ( 'id' , 'date_creation' ) -> where ( 'string' , $ string ) -> where ( 'context' , $ context ) -> first ( ) ; if ( ! $ db_string ) { $ this -> translateInsertString ( $ context , $ string ) ; return $ string ; } $ text = $ this -> translateGetString ( $ context , $ language , $ db_string -> id ) ; if ( $ text ) { $ this -> strings [ $ language ] [ $ context ] [ $ string ] = $ text ; return $ text ; } return $ string ; }
Retreive a string to translate

if it doesn't find it, put it in the database

@param  string $string
@param  string $context
@param  string $language
@return string
Retreive a string to translate