FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Trans Class Reference

Translations component. More...

Inheritance diagram for Trans:
Component Thing

Public Member Functions

 langs ()
 Available languages. More...
 
 getStr ($id, $default=false)
 Basic string getter. More...
 
 escape ($tags)
 Escape tag values (convert special characters to HTML entities). More...
 
 str ($str, $tags=null)
 Translate a string. More...
 
 id ($id, $tags=null, $default=false)
 Translate a string by ID. More...
 
 fragment ($id)
 
 __call ($func_name, $params)
 
 __invoke ($str, $tags=null)
 
- Public Member Functions inherited from Component
 __construct ($fred, $config=null)
 
 __destruct ()
 
 clientConfig ()
 Public configuration. More...
 
 config ($key, $default=null)
 Retrieve a config value. More...
 
 ping ()
 Ping function. More...
 
 filemtime ($filename)
 Filemtime with session cache. More...
 
 component ($name)
 Get a component (local or default). More...
 
 components (... $names)
 Get multiple components in an array. More...
 
- Public Member Functions inherited from Thing
 propertyExists ($property)
 Check if a property exists (public or published). More...
 
 constants ($prefix=null)
 Return all constants. More...
 
 get ($key)
 Get one or more properties. More...
 
 set ($key, $value=null)
 Set one or more properties. More...
 
 __get ($key)
 
 __set ($key, $value)
 

Data Fields

const TYPE_TAG = '+'
 Add a tag to to the tags: [+tag|value]. More...
 
const TYPE_OPTIONAL = '?'
 Optional sub-string (defaults to empty; no error): [?strId]. More...
 
const TYPE_SUBSTR = '@'
 Points to a sub-string: [@strId]. More...
 
const TYPE_TRUE = '%'
 Show section when tag value is true: {[tag]show when tag is not empty}. More...
 
const TYPE_FALSE = '!'
 Show section when tag value is false: {[!tag]show when tag is empty}. More...
 
const TYPE_COUNT = '#'
 Insert number of items in array: Array has [#arrayTag] items. More...
 
const TYPE_SUM = '='
 Sum of an array column: [=array|column|formatting]. More...
 
const TYPE_ARRAY = '*'
 Repeat section for each item (item aded to tags, including k = key, v = value - when record is. More...
 
const TYPE_DECODE = ':'
 Decode a value: [:intTag|1:foo|2:bar|default]. Set the value to '?' for a random selection. More...
 
const TYPE_JSON = '$'
 Insert a JSON encoded value. More...
 
const TYPE_RAW = '~'
 Insert value without inserting a conditional tag: [[~intTag],number]. More...
 
const MACRO_ESCAPE = 'escape'
 Escape the text between these tags (pre processing). More...
 
const MACRO_SPACE = 'space'
 Remove white-space between tags. More...
 
const MACRO_REPLACE = 'replace'
 Replace the text in attribute 'from' (regex) to 'to'. More...
 
const MACRO_UNITS = 'units'
 Split the value of the tag name into units, so it can be used as an array (units in desired. More...
 
const MACRO_CONST = 'const'
 Replace the text with the value of the constant between the tags (pre processing). More...
 
const MACRO_CACHE = 'cache'
 Cache the (processed) text (set the 'ttl' tag to use the main cache; use the 'key'. More...
 
const MACRO_FRAGMENT = 'fragment'
 Replace the tag with a placeholder and replace it with the fragment later on (with. More...
 
const MACRO_ROUTE = 'route'
 Create a (reverse) route for the controller name between the tags (attributes are params). More...
 
const MACRO_LOCATION = 'location'
 Rewrite the location between the tags (pre processing). More...
 
const MACRO_IMAGE = 'image'
 Generate an image tag for the image between the tags (the content is cached, set the 'ttl'. More...
 
const MACRO_URL = 'url'
 Load external content from the address between the tags (the content is cached, set the 'ttl'. More...
 
const MACRO_RIGHT = 'right'
 
const EVENT_FORMAT = 'trans:format:'
 
 $namespace = 'trans'
 
 $maxNested = 10
 Maximum number of times a sub-string may be nested. More...
 
 $logPrio = Log::INFO
 Prio for translation related errors (invalid tags, format, etc). More...
 
 $imageTtl = 86400
 Default cache TTL for image tag generation. More...
 
 $imageKeyPrefix = 'trans-image-'
 
 $urlTtl = 86400
 Default cache TTL for external content. More...
 
 $urlKeyPrefix = 'trans-url-'
 
 $cacheKeyPrefix = 'trans-cache-'
 
- Data Fields inherited from Component
 $filemtimeTtl = 0
 
- Data Fields inherited from Thing
const HIDDEN = 0
 Property is hidden. More...
 
const READABLE = 1
 Property is readable. More...
 
const WRITEABLE = 2
 Property is writeable. More...
 
const READWRITE = 3
 Property is readable and writeable. More...
 

Protected Member Functions

 init ()
 
 error ($message, $file=null, $line_no=null, $context=null)
 
 getStrs ($lang_id)
 Get all strings. More...
 
 macro ($str, $type, &$tags, $callback)
 
 preProcess ($str, &$tags)
 
 postProcess ($str, &$tags)
 
 value ($tag, $params, &$tags)
 
 evaluate ($expr, $tag, &$tags)
 
 formatSubstr ($value, $start, $length=null)
 
 formatReplace ($value, $search, $replace)
 
 formatRegex ($value, $pattern, $replace)
 
 format ($tag, $value, $params, &$tags)
 Format a value. More...
 
 replace ($str, $full, $type, $tag, $operator,$params, $value, &$tags, &$strs)
 Replace a tag with its value. More...
 
 brush ($str)
 Elaborate conditional parts. More...
 
 trans ($str, $tags=null)
 Translate a string. More...
 
 getRegex ()
 
 setTags ($value)
 
 getTypes ()
 
 _get ($key)
 
- Protected Member Functions inherited from Component
 init ()
 
 done ()
 
 getSession ()
 
- Protected Member Functions inherited from Thing
 publish ($property, $visibility=self::READABLE)
 Publish a property (or hide it again). More...
 
 configure ($config)
 Configure the object. More...
 
 _get ($key)
 Default getter if no specific setter is defined, and the property is also not published (readable). More...
 
 _set ($key, $value)
 Default setter if no specific setter is defined, and the property is also not published (writeable). More...
 

Protected Attributes

 $_langId = null
 
 $_filename = null
 Filename for the translations (asterisk will be replace by the langId). More...
 
 $_prefix = null
 
 $_strs = []
 
 $_tags = []
 Default tags to use with every translation. More...
 
 $_escape = []
 
 $_unescape = []
 
 $_cache = []
 
 $_types = null
 
 $_regex = null
 
- Protected Attributes inherited from Component
 $_fred = null
 
 $_config = null
 
 $_name = null
 
 $_components = []
 Local components (key = component name, value = component). More...
 
 $_session = null
 
- Protected Attributes inherited from Thing
 $_published = []
 Published properties (key = name of property, value = visibility). More...
 

Detailed Description

Translations component.

Definition at line 8 of file Trans.php.

Member Function Documentation

◆ __call()

__call (   $func_name,
  $params 
)

Definition at line 500 of file Trans.php.

◆ __invoke()

__invoke (   $str,
  $tags = null 
)

Definition at line 504 of file Trans.php.

◆ _get()

_get (   $key)
protected

Definition at line 496 of file Trans.php.

◆ brush()

brush (   $str)
protected

Elaborate conditional parts.

Parameters
string$strString with conditional parts.
Returns
string String with elaborated conditional parts.

Definition at line 402 of file Trans.php.

◆ error()

error (   $message,
  $file = null,
  $line_no = null,
  $context = null 
)
protected

Definition at line 82 of file Trans.php.

◆ escape()

escape (   $tags)

Escape tag values (convert special characters to HTML entities).

Parameters
array$tagsTags with raw values (keys starting with '!' or not escaped - '!' is removed from key).
Returns
array Escaped tags

Definition at line 212 of file Trans.php.

◆ evaluate()

evaluate (   $expr,
  $tag,
$tags 
)
protected

Definition at line 258 of file Trans.php.

◆ format()

format (   $tag,
  $value,
  $params,
$tags 
)
protected

Format a value.

Parameters
string$tagTag name.
mixed$valueTag value.
string$paramsFormatting params.
array$tagsOther tags.
Returns
string Formatted value.

Definition at line 287 of file Trans.php.

◆ formatRegex()

formatRegex (   $value,
  $pattern,
  $replace 
)
protected

Definition at line 276 of file Trans.php.

◆ formatReplace()

formatReplace (   $value,
  $search,
  $replace 
)
protected

Definition at line 272 of file Trans.php.

◆ formatSubstr()

formatSubstr (   $value,
  $start,
  $length = null 
)
protected

Definition at line 268 of file Trans.php.

◆ fragment()

fragment (   $id)

Definition at line 462 of file Trans.php.

◆ getRegex()

getRegex ( )
protected

Definition at line 470 of file Trans.php.

◆ getStr()

getStr (   $id,
  $default = false 
)

Basic string getter.

Parameters
string$idString ID.
string$defaultDefault string when ID is not found.
Returns
string

Definition at line 100 of file Trans.php.

◆ getStrs()

getStrs (   $lang_id)
protected

Get all strings.

Parameters
string$lang_idLanguage ID.
Returns
array Key = string ID, value = string.

Definition at line 91 of file Trans.php.

◆ getTypes()

getTypes ( )
protected

Definition at line 488 of file Trans.php.

◆ id()

id (   $id,
  $tags = null,
  $default = false 
)

Translate a string by ID.

Parameters
string$idString ID.
array$tagsTags to use when translating the string.
string$defaultDefault string when ID is not found.
Returns
string Translated string.

Definition at line 458 of file Trans.php.

◆ init()

init ( )
protected

Definition at line 68 of file Trans.php.

◆ langs()

langs ( )

Available languages.

Returns
array Key = ID, value = description.

Definition at line 78 of file Trans.php.

◆ macro()

macro (   $str,
  $type,
$tags,
  $callback 
)
protected

Definition at line 107 of file Trans.php.

◆ postProcess()

postProcess (   $str,
$tags 
)
protected

Definition at line 162 of file Trans.php.

◆ preProcess()

preProcess (   $str,
$tags 
)
protected

Definition at line 120 of file Trans.php.

◆ replace()

replace (   $str,
  $full,
  $type,
  $tag,
  $operator,
  $params,
  $value,
$tags,
$strs 
)
protected

Replace a tag with its value.

Parameters
string$strString to replace tag in.
string$fullFull match for the tag (including brackets).
string$typeType of tag (see TYPE_* constants).
string$tagName of the tag.
string$operatorOperator for the tag (e.g. '==').
string$paramsExtra parameters in the tag.
mixed$valueValue for the tag.
array$tagsAll available tags (values).
array$strsLoaded sub-strings.
Returns
string Original input string with the full tag replaced with its value.

Definition at line 324 of file Trans.php.

◆ setTags()

setTags (   $value)
protected

Definition at line 484 of file Trans.php.

◆ str()

str (   $str,
  $tags = null 
)

Translate a string.

Parameters
string$strBasic string with tags.
array$tagsTags to use when translating the string.
Returns
string Translated string.

Definition at line 448 of file Trans.php.

◆ trans()

trans (   $str,
  $tags = null 
)
protected

Translate a string.

Parameters
string$strBasic string with tags.
array$tagsTags to use when translating the string. Values are automaticle escaped, except when the key starts with a '!'. For keys starting with a '@' the value is used as a callback function (only called when the tag is present in the string; use '@!' prefix for callback values that should not be escaped).
Returns
string Translated string.

Definition at line 415 of file Trans.php.

◆ value()

value (   $tag,
  $params,
$tags 
)
protected

Definition at line 225 of file Trans.php.

Field Documentation

◆ $_cache

$_cache = []
protected

Definition at line 63 of file Trans.php.

◆ $_escape

$_escape = []
protected

Definition at line 61 of file Trans.php.

◆ $_filename

$_filename = null
protected

Filename for the translations (asterisk will be replace by the langId).

Definition at line 56 of file Trans.php.

◆ $_langId

$_langId = null
protected

Definition at line 55 of file Trans.php.

◆ $_prefix

$_prefix = null
protected

Definition at line 57 of file Trans.php.

◆ $_regex

$_regex = null
protected

Definition at line 66 of file Trans.php.

◆ $_strs

$_strs = []
protected

Definition at line 58 of file Trans.php.

◆ $_tags

$_tags = []
protected

Default tags to use with every translation.

Definition at line 59 of file Trans.php.

◆ $_types

$_types = null
protected

Definition at line 65 of file Trans.php.

◆ $_unescape

$_unescape = []
protected

Definition at line 62 of file Trans.php.

◆ $cacheKeyPrefix

$cacheKeyPrefix = 'trans-cache-'

Definition at line 53 of file Trans.php.

◆ $imageKeyPrefix

$imageKeyPrefix = 'trans-image-'

Definition at line 50 of file Trans.php.

◆ $imageTtl

$imageTtl = 86400

Default cache TTL for image tag generation.

Definition at line 49 of file Trans.php.

◆ $logPrio

$logPrio = Log::INFO

Prio for translation related errors (invalid tags, format, etc).

Definition at line 48 of file Trans.php.

◆ $maxNested

$maxNested = 10

Maximum number of times a sub-string may be nested.

Definition at line 47 of file Trans.php.

◆ $namespace

$namespace = 'trans'

Definition at line 46 of file Trans.php.

◆ $urlKeyPrefix

$urlKeyPrefix = 'trans-url-'

Definition at line 52 of file Trans.php.

◆ $urlTtl

$urlTtl = 86400

Default cache TTL for external content.

Definition at line 51 of file Trans.php.

◆ EVENT_FORMAT

const EVENT_FORMAT = 'trans:format:'

Definition at line 44 of file Trans.php.

◆ MACRO_CACHE

const MACRO_CACHE = 'cache'

Cache the (processed) text (set the 'ttl' tag to use the main cache; use the 'key'.

Definition at line 31 of file Trans.php.

◆ MACRO_CONST

const MACRO_CONST = 'const'

Replace the text with the value of the constant between the tags (pre processing).

Definition at line 30 of file Trans.php.

◆ MACRO_ESCAPE

const MACRO_ESCAPE = 'escape'

Escape the text between these tags (pre processing).

Definition at line 23 of file Trans.php.

◆ MACRO_FRAGMENT

const MACRO_FRAGMENT = 'fragment'

Replace the tag with a placeholder and replace it with the fragment later on (with.

Definition at line 33 of file Trans.php.

◆ MACRO_IMAGE

const MACRO_IMAGE = 'image'

Generate an image tag for the image between the tags (the content is cached, set the 'ttl'.

Definition at line 37 of file Trans.php.

◆ MACRO_LOCATION

const MACRO_LOCATION = 'location'

Rewrite the location between the tags (pre processing).

Definition at line 36 of file Trans.php.

◆ MACRO_REPLACE

const MACRO_REPLACE = 'replace'

Replace the text in attribute 'from' (regex) to 'to'.

Definition at line 25 of file Trans.php.

◆ MACRO_RIGHT

const MACRO_RIGHT = 'right'

Definition at line 41 of file Trans.php.

◆ MACRO_ROUTE

const MACRO_ROUTE = 'route'

Create a (reverse) route for the controller name between the tags (attributes are params).

Definition at line 35 of file Trans.php.

◆ MACRO_SPACE

const MACRO_SPACE = 'space'

Remove white-space between tags.

Definition at line 24 of file Trans.php.

◆ MACRO_UNITS

const MACRO_UNITS = 'units'

Split the value of the tag name into units, so it can be used as an array (units in desired.

Definition at line 26 of file Trans.php.

◆ MACRO_URL

const MACRO_URL = 'url'

Load external content from the address between the tags (the content is cached, set the 'ttl'.

Definition at line 39 of file Trans.php.

◆ TYPE_ARRAY

const TYPE_ARRAY = '*'

Repeat section for each item (item aded to tags, including k = key, v = value - when record is.

Definition at line 17 of file Trans.php.

◆ TYPE_COUNT

const TYPE_COUNT = '#'

Insert number of items in array: Array has [#arrayTag] items.

Definition at line 15 of file Trans.php.

◆ TYPE_DECODE

const TYPE_DECODE = ':'

Decode a value: [:intTag|1:foo|2:bar|default]. Set the value to '?' for a random selection.

Definition at line 19 of file Trans.php.

◆ TYPE_FALSE

const TYPE_FALSE = '!'

Show section when tag value is false: {[!tag]show when tag is empty}.

Definition at line 14 of file Trans.php.

◆ TYPE_JSON

const TYPE_JSON = '$'

Insert a JSON encoded value.

Definition at line 20 of file Trans.php.

◆ TYPE_OPTIONAL

const TYPE_OPTIONAL = '?'

Optional sub-string (defaults to empty; no error): [?strId].

Definition at line 11 of file Trans.php.

◆ TYPE_RAW

const TYPE_RAW = '~'

Insert value without inserting a conditional tag: [[~intTag],number].

Definition at line 21 of file Trans.php.

◆ TYPE_SUBSTR

const TYPE_SUBSTR = '@'

Points to a sub-string: [@strId].

Definition at line 12 of file Trans.php.

◆ TYPE_SUM

const TYPE_SUM = '='

Sum of an array column: [=array|column|formatting].

Definition at line 16 of file Trans.php.

◆ TYPE_TAG

const TYPE_TAG = '+'

Add a tag to to the tags: [+tag|value].

Definition at line 10 of file Trans.php.

◆ TYPE_TRUE

const TYPE_TRUE = '%'

Show section when tag value is true: {[tag]show when tag is not empty}.

Definition at line 13 of file Trans.php.


The documentation for this class was generated from the following file: