PEAR Manual
Prev |  | Next

# Class Summary Translation2_Decorator_DefaultText

Class Summary Translation2_Decorator_DefaultText -- Decorator to provide a fallback text for empty strings.

## DefaultText Decorator Example

When the fetched string is empty, it replaces it with the 4th parameter of the get() method, i.e. `$defaultText`. If the `defaultText` parameter is empty too, then return "$emptyPostfix.$outputString.$emptyPrefix", the three variables being class properties you can set to a custom string.

When getPage() is called, all the empty strings in the page are replaced by their stringID value.

    $tr = new Translation2($driver, $dbinfo, $params);
    $tr =& $tr->getDecorator('DefaultText');

    // %stringID% will be replaced with the stringID
    // %pageID_url% will be replaced with the pageID
    // %stringID_url% will replaced with a urlencoded stringID
    // %url% will be replaced with the targeted url
    $tr->outputString = '%stringID%<a href="%url%">(T)</a>'; //default: '%stringID%'
    $tr->url = '#';           //same as default
    $tr->emptyPrefix  = '[';  //default: empty string
    $tr->emptyPostfix = ']';  //default: empty string

Prev | Home | Next
Class Summary Translation2_Decorator_CacheMemory | Up | Class Summary Translation2_Decorator_ErrorText