src/Translate.php
public function _f(string $key, $strings, ?string $lang = null): string
    {
        if ($lang === null) {
            $lang = $this->lang;
        }
        
        if (!isset($this->data[$lang])) {
            throw new \OutOfBoundsException("Invalid language: $lang");
        }
        
        if (!isset($this->data[$lang][$key])) {
            throw new \OutOfBoundsException("Invalid key: $key");
        }
        
        if ($strings === null) {
            $strings = '';
        }
        
        if (is_string($strings) || is_float($strings) || is_int($strings)) {
            return sprintf($this->data[$lang][$key], $strings);
        }
        
        if (is_array($strings)) {
            return vsprintf($this->data[$lang][$key], $strings);
        }
        
        throw new \InvalidArgumentException('Strings must be a string or array to return a formatted localized string.');
    }
public function _f(string $key, $strings, ?string $lang = null): string
    {
        if ($lang === null) {
            $lang = $this->lang;
        }
        
        if (!isset($this->data[$lang])) {
            throw new \OutOfBoundsException("Invalid language: $lang");
        }
        
        if (!isset($this->data[$lang][$key])) {
            throw new \OutOfBoundsException("Invalid key: $key");
        }
        
        if ($strings === null) {
            $strings = '';
        }
        
        if (is_string($strings) || is_float($strings) || is_int($strings)) {
            return sprintf($this->data[$lang][$key], $strings);
        }
        
        if (is_array($strings)) {
            return vsprintf($this->data[$lang][$key], $strings);
        }
        
        throw new \InvalidArgumentException('Strings must be a string or array to return a formatted localized string.');
    }
public function _f ( string $ key , $ strings , ? string $ lang = null ) : string { if ( $ lang === null ) { $ lang = $ this -> lang ; } if ( ! isset ( $ this -> data [ $ lang ] ) ) { throw new \ OutOfBoundsException ( "Invalid language: $lang" ) ; } if ( ! isset ( $ this -> data [ $ lang ] [ $ key ] ) ) { throw new \ OutOfBoundsException ( "Invalid key: $key" ) ; } if ( $ strings === null ) { $ strings = '' ; } if ( is_string ( $ strings ) || is_float ( $ strings ) || is_int ( $ strings ) ) { return sprintf ( $ this -> data [ $ lang ] [ $ key ] , $ strings ) ; } if ( is_array ( $ strings ) ) { return vsprintf ( $ this -> data [ $ lang ] [ $ key ] , $ strings ) ; } throw new \ InvalidArgumentException ( 'Strings must be a string or array to return a formatted localized string.' ) ; }
Returns "formatted" localized text
@param string $key The key (description) of the localized text
@param string|array $strings See sprintf (string) and vsprintf (array)
@param string $lang The output language. Default is default language.
@return string The "formatted" localized text
@throws \OutOfBoundsException If the language or key is invalid.
@throws \InvalidArgumentException If the formatter strings is not a string or array.
Returns formatted localized text