\patTemplate_Function_Translate

patTemplate function that emulates gettext's behaviour

This can be used to create multi-lingual websites. When the template is read, all texts inside the Translation tags are extracted and written to a file called '$tmplname-default.ini'.

You should copy this file and translate all sentences. When the template is used the next time, the sentences will be replaced with their respective translations, according to the language you set with: $tmpl->setOption( 'lang', 'de' );

You can change this behavior with some specific options:

  • translationFile: If set, all strings for a language will be collected in one file with the specified name (without extension, that's added automatically)
  • translationUseFolders: if set, all files for a language will be stored in subfolders named after the language. This option is cumulative with the translationFile option.
  • translationAutoCreate: if set, the translation files will automatically be created if they don't exist so you do not have to create them manually.
  • translationUseLocator: per default, a locator string is added to all new sentences that need to be translated to help find them amongst the lot. You can turn this behavior off by setting this to false.
  • translationLocatorString: per default, the locator string is 'Translate', but you can change this to any string you like with this option.

$ID$

Summary

Methods
Properties
Constants
setReader()
call()
getName()
setParams()
getParam()
setTemplateReference()
_retrieveGlobalConfig()
_retrieveConfig()
_loadTranslationFile()
_unescape()
_updateTranslationFiles()
_updateTranslationFile()
_guessLanguage()
$_reader
$type
$_name
$_params
$_config
$_globalconfig
$_configLoaded
$_sentences
$_translation
$_tmpl
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$_reader

$_reader : object

reader object

Type

object

$type

$type : integer

function type

Type

integer

$_name

$_name : string

name of the function

Type

string

$_params

$_params : array

module parameters

Type

array

$_config

$_config : array

configuration of all files

Type

array

$_globalconfig

$_globalconfig : array

Stores the global configuration for the translation - this is only loaded once, and also defines general default settings.

Type

array

$_configLoaded

$_configLoaded : 

Type

$_sentences

$_sentences : array

list of all sentences

Type

array

$_translation

$_translation : array

translations of the language files

Type

array

$_tmpl

$_tmpl : object

reference to the patTemplate object that instantiated the module

Type

object

Methods

setReader()

setReader(  $reader) 

set the reference to the reader object

Parameters

$reader

call()

call(  $params,   $content) : string

call the function

Parameters

$params
$content

Returns

string —

content to insert into the template

getName()

getName() : string

get the name of the module

Returns

string —

name of the module

setParams()

setParams(  $params,   $clear = false) 

sets parameters of the module

Parameters

$params
$clear

getParam()

getParam(  $name) : mixed

gets a parameter of the module

Parameters

$name

Returns

mixed —

value of the parameter

setTemplateReference()

setTemplateReference(  $tmpl) 

set a reference to the patTemplate object that instantiated the reader

Parameters

$tmpl

_retrieveGlobalConfig()

_retrieveGlobalConfig() : boolean

get the global configuration

This method fetches the selected language and the translation folder as it is shared by all templates.

Returns

boolean —

currently always returns true

_retrieveConfig()

_retrieveConfig(  $input) : boolean

retrieve configuration

This method sets the used files and loads the original sentence file, if it exists.

Parameters

$input

Returns

boolean —

true on success

_loadTranslationFile()

_loadTranslationFile(  $input) : boolean

load the translation file

Parameters

$input

Returns

boolean —

true on success

_unescape()

_unescape(  $text) : string

unsecape the text that has been read from the translation file

Parameters

$text

Returns

string

_updateTranslationFiles()

_updateTranslationFiles(  $input,   $key,   $content) : boolean

Updates all available translation files with the new string to translate.

Parameters

$input
$key
$content

Returns

boolean

_updateTranslationFile()

_updateTranslationFile(  $input,   $key,   $content) : boolean

Updates a single translation file with the specified new string

Parameters

$input
$key
$content

Returns

boolean

_guessLanguage()

_guessLanguage() : array

Tries to guess the user's language according to the browser's language setting

Returns

array —

Array containing all accepted languages