root/branches/gettext/examples/example_api_locale_gettext.php

Revision 394, 2.5 kB (checked in by gerd, 1 year ago)

Switched to patI18n

  • removed all setLocale / getLocale functions from patForms, elements etc.
  • use patI18n::dgettext with textdomain "patForms"
  • added patI18n example
  • added helper script to setup patI18n
  • mended examples accordingly
  • Property svn:keywords set to "Id"
Line 
1 <?php
2 /**
3  * Example that shows how to set a locale or error messages
4  *
5  * $Id: example_api_locale.php 371 2006-08-08 15:45:57Z gerd $
6  *
7  * @access        public
8  * @package        patForms
9  * @subpackage    Examples
10  * @author        Sebastian Mordziol <argh@php-tools.net>
11  * @license        LGPL, see license.txt for details
12  * @link        http://www.php-tools.net
13  */
14
15     /**
16      * Main examples prepend file, needed *only* for the examples framework!
17      */
18     include_once 'patExampleGen/prepend.php';
19     $exampleGen->displayHead( 'Example' );
20
21     
22     // EXAMPLE START ------------------------------------------------------
23
24     /**
25      * main patForms class
26      */
27     require_once $neededFiles['patForms'];
28     
29     /**
30      * patErrorManager class
31      */
32     require_once $neededFiles['patErrorManager'];
33     
34     /**
35      * localisation stuff
36      */
37     require_once $neededFiles['patI18n_configure'];
38
39
40     // element definitions for this example
41     $elementsDefinition = array(
42         'username' => array(
43             'type' => 'String',
44             'attributes' => array(
45                 'required'        =>    'yes',
46                 'display'        =>    'yes',
47                 'edit'            =>    'yes',
48                 'label'            =>    'Nickname',
49                 'description'    =>    'Enter your nickname here.',
50                 'maxlength'        =>    '5',
51                 'minlength'        =>    '4',
52                 'default'        =>    'The Argh',
53                 'title'            =>    'Username',
54             ),
55         ),
56         'switch' => array(
57             'type' => 'Switch',
58             'attributes' => array(
59                 'required'      =>  'yes',
60                 'display'       =>  'yes',
61                 'edit'          =>  'yes',
62                 'label'         =>  'Trigger',
63                 'description'   =>  'Pull the trigger',
64                 'title'         =>  'Trigger',
65             ),
66         ),
67     );
68     
69  
70     echo "Er, just some sample output to warm up...<br /><br />";
71     echo 'E-Mail domain could not be found: <b>' . dgettext( 'patForms', 'E-Mail domain could not be found.' ) . "</b><br />\n";
72     echo 'A choice is required, please select an option from the list: <b>' . dgettext( 'patForms', 'A choice is required, please select an option from the list.' ) . "</b><br />\n";
73     echo "<br /><br />";
74  
75     // create our form
76     $form =& patForms::createForm( $elementsDefinition );
77     
78     // tell the form it has been submitted
79     $form->setSubmitted( true );
80
81     // validate the element - this will always fail here on purpose to show
82     // the error message
83     $form->validateForm();
84     
85     // display the errors
86     displayErrors( $form ); // see patExampleGen/customFunctions.php
87
88     
89     // EXAMPLE END ------------------------------------------------------
90     $exampleGen->displayFooter();
91 ?>
92
Note: See TracBrowser for help on using the browser.