Phrase rendering class.

package XenForo_Core

 Methods

Constructor

__construct(string | array $phraseName, array $params, boolean | array $insertParamsEscaped) 

Parameters

$phraseName

stringarray

Phrase name (or, array(phraseName, arg1 => x, arg2 => y...)

$params

array

Key-value parameters

$insertParamsEscaped

booleanarray

See {@link $_insertParamsEscaped}

Implicit string cast renders the phrase.

__toString() : string

Returns

string

Gets the language ID that phrases will be retrieived from.

getLanguageId() : integer

Returns

integer

Gets the params.

getParams() : array

Returns

array

Gets the phrase name.

getPhraseName() : string

Returns

string

Bulk load all phrases that are required.

loadPhrases() 

Specify a phrase that needs to be preloaded for use later.

preloadPhrase(string $phraseName) 

This is useful if you think a render is going to be called before the phrase you require is to be used.

Parameters

$phraseName

string

Phrase to preload

Renders the specified phrase and returns the output.

render(boolean | null $phraseNameOnInvalid) : string

Parameters

$phraseNameOnInvalid

booleannull

If the phrase is invalid, return the phrase name (otherwise, empty string); if null, use default setting

Returns

string

Resets the phrase system state.

reset() 

Sets the param escaping callback function.

setEscapeCallback(false | callback $callback) 

Parameters

$callback

falsecallback

Sets whether inserted parameters should be automatically escaped.

setInsertParamsEscaped($insertParamsEscaped) 

see \global\$_insertParamsEscaped

Parameters

$insertParamsEscaped

array|boolean

Sets the language ID that phrases will be retrieved from.

setLanguageId(integer $languageId) 

Parameters

$languageId

integer

Add an array of params to the phrase.

setParams(array $params) 

Overwrites parameters with the same name.

Parameters

$params

array

Manually sets a phrase.

setPhrase(string $phraseName, string $phraseValue) 

This is primarily useful for testing.

Parameters

$phraseName

string

Name of the phrase

$phraseValue

string

Value for the phrase

Sets the value for the phrase name on invalid setting.

setPhraseNameOnInvalid(boolean $value) 

This controls the behavior with an invalid phrase name. If true, output phrase name; otherwise, nothing.

Parameters

$value

boolean

Manually sets the cache values for collection of phrases.

setPhrases(array $phrases) 

Parameters

$phrases

array

Escapes the named parameter if necessary, based on {@link $_insertParamsEscaped).

_escapeParam(string $paramName, string $paramValue) : string

Parameters

$paramName

string

Name of parameter

$paramValue

string

Value of parameter

Returns

stringEscaped parameter

Load the named phrase.

_loadPhrase(string $phraseName) : string

Parameters

$phraseName

string

Phrase name

Returns

stringCompiled version of the phrase

Callback function for regular expression to replace a named parameter with a value.

_replaceParam(array $match) : string

Parameters

$match

array

Match array. Looks in key "param".

Returns

stringReplaced value

 Properties

 

The function that should be called to escape phrase parameters.

$_escapeCallback 

This should be set by the view renderer. Set it to false to disable escaping completely.

param

false|callback

 

Whether the params should be inserted into the phrase raw or escaped.

$_insertParamsEscaped : boolean | array

If this is true or false, it applies to all params. If it is an array, the individual params are looked up as keys and the value is treated as a a boolean; params that aren't set will be escaped.

 

The ID of the language that phrases will be retrieved from.

$_languageId : integer

 

Key-value params to make available in the phrase.

$_params : array

 

Cached phrase data.

$_phraseCache : array

Key is the phrase name; value is the phrase text.

 

Name of the phrase to load.

$_phraseName : string

 

Controls whether the phrase name should be output when the value is invalid.

$_phraseNameOnInvalid : boolean

 

A list of phrases that still need to be loaded.

$_toLoad : array

Key is the phrase name.