root/branches/gettext/examples/example_api_locale.php

Revision 394, 2.3 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:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /**
3  * Example that shows how to set a locale or error messages
4  *
5  * $Id$
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      * internationalisaion
36      */
37     require_once $neededFiles['patI18n'];
38     
39     // Internal
40     $moduleConf =   array();
41     patI18n::addModule( 'Internal', $moduleConf );
42     
43     // Gettext
44     $moduleConf =   array(
45                 'domain'    =>  'this_domain_is_not_used',
46                 'dir'       =>  '/tmp',
47                 'domains'   =>  array(
48                     array(
49                             'domain'    =>  'patForms',
50                             'dir'       =>  dirname( __FILE__ ) . '/locales',
51                         )
52                     )
53         );
54     patI18n::addModule( 'Gettext', $moduleConf );
55     patI18n::setLocale( $_GET['lang'] );
56     
57     // all the above is done by the following include
58     // require_once $neededFiles['patI18n_configure'];
59
60     // element definitions for this example
61     $elementsDefinition = array(
62         'username' => array(
63             'type' => 'String',
64             'attributes' => array(
65                 'required'        =>    'yes',
66                 'display'        =>    'yes',
67                 'edit'            =>    'yes',
68                 'label'            =>    'Nickname',
69                 'description'    =>    'Enter your nickname here.',
70                 'maxlength'        =>    '5',
71                 'minlength'        =>    '4',
72                 'default'        =>    'The Argh',
73                 'title'            =>    'Username',
74             ),
75         ),
76     );
77     
78     // create our form
79     $form =& patForms::createForm( $elementsDefinition );
80     
81     // tell the form it has been submitted
82     $form->setSubmitted( true );
83
84     // validate the element - this will always fail here on purpose to show
85     // the error message
86     $form->validateForm();
87     
88     // display the errors
89     displayErrors( $form ); // see patExampleGen/customFunctions.php
90
91
92     
93     
94     // EXAMPLE END ------------------------------------------------------
95     $exampleGen->displayFooter();
96 ?>
97
Note: See TracBrowser for help on using the browser.