phpPhrasebook
[ class tree: phpPhrasebook ] [ index: phpPhrasebook ] [ all elements ]

Class: Phrasebook

Source Location: Program_Root/src/Phrasebook.php

Class Overview


Implements the Phrasebook pattern


Author(s):

Methods


Child classes:

PhrasebookSql
Implements the Phrasebook pattern for SQL statements

Inherited Variables

Inherited Methods


Class Details

[line 134]
Implements the Phrasebook pattern

This class implements the phrasebook pattern, as documented by Yonat Sharon and Rani Pinchuk in their paper, The Phrasebook Pattern available at http://jerry.cs.uiuc.edu/~plop/plop2k/proceedings/Pinchuk/Pinchuk.pdf. It uses similar calls and XML document format to Rani Pinchuk's Class::Phrasebook module for Perl. The following documentation detailing the XML format is from the Class::Phrasebook module. (No reason to rewrite it)

<snip>

This class implements the Phrasebook pattern. It lets us create dictionaries of phrases. Each phrase can be accessed by a unique key. Each phrase may have placeholders. Group of phrases are kept in a dictionary. ... The phrases are kept in an XML document.

The XML document type definition is as followed:

 <?xml version="1.0"?>
 <!DOCTYPE phrasebook [
	       <!ELEMENT phrasebook (dictionary)*>              
	       <!ELEMENT dictionary (phrase)*>
               <!ATTLIST dictionary name CDATA #REQUIRED>
               <!ELEMENT phrase (#PCDATA)>
               <!ATTLIST phrase name CDATA #REQUIRED>
 ]>
Example for XML file:
 <?xml version="1.0"?>
 <!DOCTYPE phrasebook [
	       <!ELEMENT phrasebook (dictionary)*>              
	       <!ELEMENT dictionary (phrase)*>
               <!ATTLIST dictionary name CDATA #REQUIRED>
               <!ELEMENT phrase (#PCDATA)>
               <!ATTLIST phrase name CDATA #REQUIRED>
 ]>
 <phrasebook>
 <dictionary name="EN">

 <phrase name="HELLO_WORLD">
            Hello World!!!
 </phrase>

 <phrase name="THE_HOUR">
            The time now is $hour. 
 </phrase>

 <phrase name="ADDITION">
            add $a and $b and you get $c
 </phrase>


 <!-- my name is the same in English Dutch and French. -->
 <phrase name="THE_AUTHOR">
            Rani Pinchuk
 </phrase>
 </dictionary>

 <dictionary name="FR">
 <phrase name="HELLO_WORLD">
            Bonjour le Monde!!!
 </phrase>

 <phrase name="THE_HOUR">
            Il est maintenant $hour. 
 </phrase>

 <phrase name="ADDITION">
            $a + $b = $c
 </phrase>

 </dictionary>

 <dictionary name="NL">
 <phrase name="HELLO_WORLD">
            Hallo Werld!!!
 </phrase>

 <phrase name="THE_HOUR">
            Het is nu $hour. 
 </phrase>

 <phrase name="ADDITION">
            $a + $b = $c
 </phrase>

 </dictionary>

 </phrasebook>

Each phrase should have a unique name. Within the phrase text we can place placeholders. When get method is called, those placeholders will be replaced by their value.

</snip>

Example:


require ("Phrasebook.php");

$hPhrase = new Phrasebook("mydict.xml");
$hPhrase->load("EN");
print $hPhrase->getPhrase("ADDITION", array("a"=>"1",
                                            "b"=>"2",
                                            "c"=>"3"));




Tags:

author:  Andrew Barilla <abarilla@users.sourceforge.net>


[ Top ]


Class Methods


constructor Phrasebook [line 158]

Phrasebook Phrasebook( string $a_stFileName)

Constructor for Phrasebook class.



Tags:



Parameters:

string   $a_stFileName   a_stFileName The filename of the xml phrasebook document to read.

[ Top ]

method getDictionaryName [line 264]

string getDictionaryName( )

Returns the name of the dictionary currently in use



Tags:

return:  The name of the current dictionary


[ Top ]

method getPhrase [line 235]

string getPhrase( string $a_stName, [array $a_astValues = array()])

Returns the phrase from the dictionary and will substitute variables when appropriate.



Tags:

return:  The phrase with variables replaced if appropriate


Overridden in child classes as:

PhrasebookSql::getPhrase()
Returns the phrase from the dictionary and will substitute variables when appropriate.

Parameters:

string   $a_stName   a_stName The key of the phrase to return
array   $a_astValues   a_astValues Array of strings to replace variables in the phrase with

[ Top ]

method getRemoveNewLines [line 291]

boolean getRemoveNewLines( )

Returns the value of the RemoveNewLines setting



Tags:

return:  The current value of the RemoveNewLines setting


[ Top ]

method load [line 188]

void load( string $a_stDictionary)

Loads the dictionary from the xml file into memory.

Calling this more than once will not reset the previous dictionary but will instead override and add to it.




Parameters:

string   $a_stDictionary   a_stDictionary The filename of the dictionary to read from the phrasebook

[ Top ]

method setDictionaryName [line 278]

void setDictionaryName( string $a_stDictionary)

Registers the name of the dictionary to use next time the load function is called.



Parameters:

string   $a_stDictionary   a_stDictionary The name of the dictionary to use

[ Top ]

method setFileName [line 174]

void setFileName( string $a_stFileName)

Registers the name of the XML phrasebook file to use next time the load function is called.

Currently, this looks in the working directory for the XML file.




Parameters:

string   $a_stFileName   a_stFileName The filename of the xml phrasebook document to read.

[ Top ]

method setRemoveNewLines [line 306]

void setRemoveNewLines( boolean $a_boRemoveNewLines)

Sets the value of the RemoveNewLines setting.

When true, new lines will be stripped when calling the getPhrase method. When false, will leave phrases intact.




Parameters:

boolean   $a_boRemoveNewLines   a_boRemoveNewLines The value of the RemoveNewLines setting

[ Top ]


Documentation generated on Fri, 25 Jul 2003 23:23:40 -0400 by phpDocumentor 1.2.1