Class \Scrivo\I18n

Class for Scrivo internationalization (i18n) resources.

This is a class to create a set of i18n key value pairs. By default the created instance will use Scrivo's own set of i18n resources, but it is possible to use your own set(s).

An i18n resource file is a PHP script that declares a single array variabele ($I18N_TEXT) that contains the i18n key value pairs, where the keys are the english texts and the values contain the translations, f.i. the file "nl_NL.php" might contain the following:

"Annuleer"); ?>

The file name needs to be named after the language set it contains: "nl_NL.php" contains the Dutch i18n resources. It is of course strongly advised to use the UTF-8 encoding for your internationalization files.

Because we're dealing with hard coded data and it will be excessively cumbersome to deal I18N keys if you'll have to use the \Scrivo\String wrappers, you can use plain strings as i18n keys.

Typical usage:

$i18n = new \Scrivo\I18n(new \Scrivo\String("nl_NL")); echo $i18n["Cancel"];

Implements
Defined in: I18n.php.


Constructor summary

Attr. Name / Description
public

I18n($langCode, $dir)

Create a set of internationalization key/value pairs for a given language.

Member summary

Attr. Type Name Description
private array $data The i18n key value pairs, where the keys are the English texts and the values contain the translations.

Method summary

Attr. Type Name / Description
public

offsetExists($offset)

Check if the specified index location in this string is valid.

public string

offsetGet($i18nKey)

Get an i18n entry from a set using array brackets.

public

offsetSet($offset, $value)

Illegal method: set a character at a specified index location.

public

offsetUnset($offset)

Illegal method: unset a character at a specified index location.

 


Constructor

public I18n(\Scrivo\String $langCode, \Scrivo\String $dir=null)

Create a set of internationalization key/value pairs for a given language.

Parameters:

Type Name Def. Description
\Scrivo\String $langCode

The language code for which to create the set of resources for.

\Scrivo\String $dir null

An optional directory for an alternative location for the i18n resource file.

Throws:

Exception Type Description
\Exception If no 1i8n resource file was found.

Members


				
private array $data

The i18n key value pairs, where the keys are the English texts and the values contain the translations.


Methods

public offsetExists(int $offset)

Check if the specified index location in this string is valid.

Note that this method is part of the implementation of ArrayAccess. It is assumed that i18n keys are always set: if not it is pretended it's set and key itself is returned. So this method implementation is not relevant and throws an exception if called.

Parameters:

Type Name Def. Description
int $offset

Throws:

Exception Type Description
\Scrivo\SystemException If this method is called.
public string offsetGet(string $i18nKey)

Get an i18n entry from a set using array brackets.

Note that this method is part of the implementation of ArrayAccess and should not be called from another context.

Parameters:

Type Name Def. Description
string $i18nKey

A character offet in the string.

Returns:

string Get an i18n entry from a set using array brackets.

public offsetSet(int $offset, string $value)

Illegal method: set a character at a specified index location.

Note that this method is part of the implementation of ArrayAccess. I18n sets are inmutable so this method implementation is not relevant and throws an exception if called.

Parameters:

Type Name Def. Description
int $offset
string $value

Throws:

Exception Type Description
\Scrivo\SystemException If this method is called.
public offsetUnset(int $offset)

Illegal method: unset a character at a specified index location.

Note that this method is part of the implementation of ArrayAccess. I18n sets are inmutable so this method implementation is not relevant and throws an exception if called.

Parameters:

Type Name Def. Description
int $offset

Throws:

Exception Type Description
\Scrivo\SystemException If this method is called.

Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013