MockLanguage
extends Language
in package
Handle system messages and localization.
Locale-based, built on top of PHP internationalization.
Table of Contents
- $data : mixed
- Stores the data that should be returned by the 'requireFile()' method.
- $intlSupport : bool
- Boolean value whether the intl libraries exist on the system.
- $language : array<string|int, mixed>
- Stores the retrieved language lines from files for faster retrieval on second use.
- $loadedFiles : array<string|int, mixed>
- Stores filenames that have been loaded so that we don't load them again.
- $locale : string
- The current language/locale to work with.
- __construct() : mixed
- disableIntlSupport() : mixed
- Arbitrarily turnoff internationalization support for testing
- getLine() : string|array<string|int, string>
- Parses the language string for a file, loads the file, if necessary, getting the line.
- getLocale() : string
- setData() : $this
- Sets the data that should be returned by the 'requireFile()' method to allow easy overrides during testing.
- setLocale() : $this
- Sets the current locale to use when performing string lookups.
- formatMessage() : string|array<string|int, mixed>
- Advanced message formatting.
- getTranslationOutput() : array<string|int, mixed>|string|null
- load() : void|array<string|int, mixed>
- Loads a language file in the current locale. If $return is true, will return the file's contents, otherwise will merge with the existing language lines.
- parseLine() : array<string|int, mixed>
- Parses the language string which should include the filename as the first segment (separated by period).
- requireFile() : array<string|int, mixed>
- Provides an override that allows us to set custom data to be returned easily during testing.
Properties
$data
Stores the data that should be returned by the 'requireFile()' method.
protected
mixed
$data
$intlSupport
Boolean value whether the intl libraries exist on the system.
protected
bool
$intlSupport
= false
$language
Stores the retrieved language lines from files for faster retrieval on second use.
protected
array<string|int, mixed>
$language
= []
$loadedFiles
Stores filenames that have been loaded so that we don't load them again.
protected
array<string|int, mixed>
$loadedFiles
= []
$locale
The current language/locale to work with.
protected
string
$locale
Methods
__construct()
public
__construct(string $locale) : mixed
Parameters
- $locale : string
Return values
mixed —disableIntlSupport()
Arbitrarily turnoff internationalization support for testing
public
disableIntlSupport() : mixed
Return values
mixed —getLine()
Parses the language string for a file, loads the file, if necessary, getting the line.
public
getLine(string $line[, array<string|int, mixed> $args = [] ]) : string|array<string|int, string>
Parameters
- $line : string
-
Line.
- $args : array<string|int, mixed> = []
-
Arguments.
Return values
string|array<string|int, string> —Returns line.
getLocale()
public
getLocale() : string
Return values
string —setData()
Sets the data that should be returned by the 'requireFile()' method to allow easy overrides during testing.
public
setData(string $file, array<string|int, mixed> $data[, string|null $locale = null ]) : $this
Parameters
- $file : string
- $data : array<string|int, mixed>
- $locale : string|null = null
Return values
$this —setLocale()
Sets the current locale to use when performing string lookups.
public
setLocale([string $locale = null ]) : $this
Parameters
- $locale : string = null
Return values
$this —formatMessage()
Advanced message formatting.
protected
formatMessage(string|array<string|int, mixed> $message[, array<string|int, mixed> $args = [] ]) : string|array<string|int, mixed>
Parameters
- $message : string|array<string|int, mixed>
-
Message.
- $args : array<string|int, mixed> = []
-
Arguments.
Return values
string|array<string|int, mixed> —Returns formatted message.
getTranslationOutput()
protected
getTranslationOutput(string $locale, string $file, string $parsedLine) : array<string|int, mixed>|string|null
Parameters
- $locale : string
- $file : string
- $parsedLine : string
Return values
array<string|int, mixed>|string|null —load()
Loads a language file in the current locale. If $return is true, will return the file's contents, otherwise will merge with the existing language lines.
protected
load(string $file, string $locale[, bool $return = false ]) : void|array<string|int, mixed>
Parameters
- $file : string
- $locale : string
- $return : bool = false
Return values
void|array<string|int, mixed> —parseLine()
Parses the language string which should include the filename as the first segment (separated by period).
protected
parseLine(string $line, string $locale) : array<string|int, mixed>
Parameters
- $line : string
- $locale : string
Return values
array<string|int, mixed> —requireFile()
Provides an override that allows us to set custom data to be returned easily during testing.
protected
requireFile(string $path) : array<string|int, mixed>
Parameters
- $path : string