class vB_Phrase

Phrase Stores a phrasegroup / key pair for deferred rendering.

When a new phrase is created, the phrasegroup and key is cached. Whenever a phrase is rendered to a string, all of the phrasegroups / keys are fetched in a single query and the phrasegroup cache is purged.

Traits

Properties

static protected array $phrasekey_cache Local phrasekey cache.
static protected array $phrase_cache Local phrase cache.
static protected array $precache Precached phrases.
static protected array $precached_groups Groups that were loaded in the precache.
static protected array $uncachable_groups Phrasegroups that cannot be cached.
protected string $phrasegroup The phrasegroup of the phrase.
protected string $phrasekey The phrasekey of the phrase.
protected array $parameters Parameters to parse with the phrase.
static protected int $languageid The languageid to use throughout the session.

Methods

__sleep()

No description

__wakeup()

No description

__construct($phrasegroup, $phrasekey, $parameters = null)

Constructor.

static 
addPhrases(array $phrasegroups)

Allows existing phrases to be added.

static 
setLanguage($languageid = NULL)

Sets the language id to use for phrasing.

static bool
groupCachable(string $phrasegroup)

Checks if a phrasegroup is cachable.

static 
cachePhraseKey(string $phrasegroup, string $phrasekey)

Caches a phrasekey.

static 
clearCache()

Clears the phrasekey cache.

static 
fetchCache()

Fetches the phrases for all of the keys in the cache.

static 
preCache(array $phrases, array $groups)

Allows prefetched phrases to be assigned to vB_Phrase.

static string
fetchSinglePhrase(string $phrasekey, array $parameters = array())

Fetches a rendered phrase.

static string
replaceVars($phrase, $params)

Replaces '{X} with variables

static 
setPhraseGroup(string $groupname, array $phrases)

Sets a phrasegroup and removes it from the key cache.

string
__toString()

Renders the phrase to a string.

static string
fetchPhrase(string $phrasegroup, string $phrasekey, array $parameters = array())

Fetches a rendered phrase.

static string
fetchUncachablePhrase(string $phrasegroup, string $phrasekey, string $languageid = false)

Fetches a phrase without using any caching.

static string
parsePhrase(vB_Phrase $phrase, array $parameters = null)

Parses the tokens in a string with the given values.

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

at line 128
__construct($phrasegroup, $phrasekey, $parameters = null)

Constructor.

When a phrase is constructed, the phrasegroup and phrasekey are cached until the next time a phrase is rendered to a string.

Parameters

$phrasegroup
$phrasekey
$parameters

at line 152
static addPhrases(array $phrasegroups)

Allows existing phrases to be added.

$phrases should be in the form array(phrasegroup => array(phrasekey => phrase))

Parameters

array $phrasegroups array string $phrases

at line 169
static setLanguage($languageid = NULL)

Sets the language id to use for phrasing.

Parameters

$languageid

at line 216
static bool groupCachable(string $phrasegroup)

Checks if a phrasegroup is cachable.

Some phrasegroups are not cachable, such as error or redirect messages.

Parameters

string $phrasegroup
  • The name of the phrasegroup to check

Return Value

bool

at line 232
static cachePhraseKey(string $phrasegroup, string $phrasekey)

Caches a phrasekey.

Parameters

string $phrasegroup
string $phrasekey

at line 252
static clearCache()

Clears the phrasekey cache.

This is useful when it is known that all previously cached phrases are no longer needed; such as when a redirect or user error occurs.

at line 261
static protected fetchCache()

Fetches the phrases for all of the keys in the cache.

at line 314
static preCache(array $phrases, array $groups)

Allows prefetched phrases to be assigned to vB_Phrase.

Parameters

array $phrases
  • Assoc array of key => phrase
array $groups
  • Array of groups in the precache

at line 345
static string fetchSinglePhrase(string $phrasekey, array $parameters = array())

Fetches a rendered phrase.

If the phrase is not in the local phrase cache, then the phrasekey cache is loaded and purged.

Parameters

string $phrasekey
  • The phrasekey of the phrase
array $parameters mixed - Array of parameters to parse into the phrase

Return Value

string
  • The translated phrase

at line 381
static protected string replaceVars($phrase, $params)

Replaces '{X} with variables

Parameters

$phrase
$params

Return Value

string

at line 403
static setPhraseGroup(string $groupname, array $phrases)

Sets a phrasegroup and removes it from the key cache.

Parameters

string $groupname
  • The group to set
array $phrases string $phrases - Array of key => phrase

at line 423
string __toString()

Renders the phrase to a string.

Can be used inline.

Return Value

string

at line 449
static string fetchPhrase(string $phrasegroup, string $phrasekey, array $parameters = array())

Fetches a rendered phrase.

If the phrase is not in the local phrase cache, then the phrasekey cache is loaded and purged.

Parameters

string $phrasegroup
  • The phrase group where the phrase is located. Can be null.
string $phrasekey
  • The phrasekey of the phrase
array $parameters mixed - Array of parameters to parse into the phrase

Return Value

string
  • The translated phrase

at line 501
static protected string fetchUncachablePhrase(string $phrasegroup, string $phrasekey, string $languageid = false)

Fetches a phrase without using any caching.

This is useful for uncachable phrases such as error messages and redirect messages.

Parameters

string $phrasegroup
  • The phrase group where the phrase is located
string $phrasekey
  • The phrasekey of the phrase
string $languageid
  • Id of the language to fetch from

Return Value

string
  • The translated phrase

at line 556
static string parsePhrase(vB_Phrase $phrase, array $parameters = null)

Parses the tokens in a string with the given values.

Parameters

vB_Phrase $phrase | string $phrase - The phrase to parse
array $parameters mixed $parameters - The values to parse into the phrase

Return Value

string
  • The resulting string