Class::Phrasebook Class::Phrasebook 7 of 23 : [PREV] [NEXT]

The Module

Let us see how we use that class to generate some error codes in different languages (English and Dutch for example).

The phrasebook is a simple XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!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="MISUSE_OF_MANUAL_TEMPLATE_NAME">
The name $name can be used only as manual template
</phrase>
...
</dictionary>
<dictionary name="NL">
<phrase name="MISUSE_OF_MANUAL_TEMPLATE_NAME">
De naam $name mag enkle gebriuk worden als webboek template
</phrase>
...
</dictionary>
</phrasebook>
  • The phrasebook file starts with the Document Type Definition (DTD).
  • This is used by the XML parser to validate the XML code.
  • Then we open the definition of the phrasebook.
  • Inside we have one or more definitions of dictionaries.
  • Each dictionary will hold the phrases.
  • The first dictionary is taken as the default dictionary:
  • If a phrase is missing in another dictionary, it will be taken from the first one.
  • The phrases can hold placeholders.
  • The placeholders look exactly like Perl scalar variables.

© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/