File: Zend_Form-I18n.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (195 lines) | stat: -rw-r--r-- 8,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.form.i18n">
    <title>Internationalization of Zend_Form</title>

    <para>
        Increasingly, developers need to tailor their content for multiple
        languages and regions. <classname>Zend_Form</classname> aims to make such a task trivial,
        and leverages functionality in both <link
            linkend="zend.translate">Zend_Translate</link> and <link
            linkend="zend.validate">Zend_Validate</link> to do so.
    </para>

    <para>
        By default, no internationalisation (I18n) is performed. To turn on I18n
        features in <classname>Zend_Form</classname>, you will need to instantiate a
        <classname>Zend_Translate</classname> object with an appropriate adapter, and
        attach it to <classname>Zend_Form</classname> and/or <classname>Zend_Validate</classname>.
        See the <link linkend="zend.translate">Zend_Translate
            documentation</link> for more information on creating the translate
        object and translation files
    </para>

    <note>
        <title>Translation Can Be Turned Off Per Item</title>

        <para>
            You can disable translation for any form, element, display group, or
            sub form by calling its <methodname>setDisableTranslator($flag)</methodname>
            method or passing a <property>disableTranslator</property> option to the
            object. This can be useful when you want to selectively disable
            translation for individual elements or sets of elements.
        </para>
    </note>

    <sect2 id="zend.form.i18n.initialization">
        <title>Initializing I18n in Forms</title>

        <para>
            In order to initialize I18n in forms, you will need either a
            <classname>Zend_Translate</classname> object or a
            <classname>Zend_Translate_Adapter</classname> object, as detailed in the
            <classname>Zend_Translate</classname> documentation. Once you have a
            translation object, you have several options:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis>Easiest:</emphasis> add it to the registry. All I18n
                    aware components of Zend Framework will autodiscover a translate
                    object that is in the registry under the 'Zend_Translate' key
                    and use it to perform translation and/or localization:
                </para>

                <programlisting language="php"><![CDATA[
// use the 'Zend_Translate' key; $translate is a Zend_Translate object:
Zend_Registry::set('Zend_Translate', $translate);
]]></programlisting>

                <para>
                    This will be picked up by <classname>Zend_Form</classname>,
                    <classname>Zend_Validate</classname>, and
                    <classname>Zend_View_Helper_Translate</classname>.
                </para>
            </listitem>

            <listitem>
                <para>
                    If all you are worried about is translating validation error
                    messages, you can register the translation object with
                    <classname>Zend_Validate_Abstract</classname>:
                </para>

                <programlisting language="php"><![CDATA[
// Tell all validation classes to use a specific translate adapter:
Zend_Validate_Abstract::setDefaultTranslator($translate);
]]></programlisting>
            </listitem>

            <listitem>
                <para>
                    Alternatively, you can attach to the <classname>Zend_Form</classname>
                    object as a global translator. This has the side effect of also
                    translating validation error messages:
                </para>

                <programlisting language="php"><![CDATA[
// Tell all form classes to use a specific translate adapter, as well
// as use this adapter to translate validation error messages:
Zend_Form::setDefaultTranslator($translate);
]]></programlisting>
            </listitem>

            <listitem>
                <para>
                    Finally, you can attach a translator to a specific form instance
                    or to specific elements using their <methodname>setTranslator()</methodname>
                    methods:
                </para>

                <programlisting language="php"><![CDATA[
// Tell *this* form instance to use a specific translate adapter; it
// will also be used to translate validation error messages for all
// elements:
$form->setTranslator($translate);

// Tell *this* element to use a specific translate adapter; it will
// also be used to translate validation error messages for this
// particular element:
$element->setTranslator($translate);
]]></programlisting>
            </listitem>
        </itemizedlist>
    </sect2>

    <sect2 id="zend.form.i18n.standard">
        <title>Standard I18n Targets</title>

        <para>
            Now that you've attached a translation object to, what exactly can
            you translate by default?
        </para>

        <itemizedlist>
            <listitem>
                <para>
                    <emphasis>Validation error messages.</emphasis> Validation
                    error messages may be translated. To do so, use the various
                    error code constants from the <classname>Zend_Validate</classname>
                    validation classes as the message IDs. For more information
                    on these codes, see the <link
                        linkend="zend.validate">Zend_Validate</link>
                    documentation.
                </para>

                <para>
                    Alternately, as of 1.6.0, you may provide translation
                    strings using the actual error messages as message
                    identifiers. This is the preferred use case for 1.6.0 and
                    up, as we will be deprecating translation of message keys in
                    future releases.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>Labels.</emphasis> Element labels will be
                    translated, if a translation exists.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>Fieldset Legends.</emphasis> Display groups and
                    sub forms render in fieldsets by default. The Fieldset
                    decorator attempts to translate the legend before rendering
                    the fieldset.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>Form and Element Descriptions.</emphasis> All form
                    types (element, form, display group, sub form) allow
                    specifying an optional item description. The Description
                    decorator can be used to render this, and by default will
                    take the value and attempt to translate it.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>Multi-option Values.</emphasis> for the various
                    items inheriting from <classname>Zend_Form_Element_Multi</classname>
                    (including the MultiCheckbox, Multiselect, and Radio
                    elements), the option values (not keys) will be translated
                    if a translation is available; this means that the option
                    labels presented to the user will be translated.
                </para>
            </listitem>

            <listitem>
                <para>
                    <emphasis>Submit and Button Labels.</emphasis> The various
                    Submit and Button elements (Button, Submit, and Reset) will
                    translate the label displayed to the user.
                </para>
            </listitem>
        </itemizedlist>
    </sect2>
</sect1>
<!--
vim:se ts=4 sw=4 tw=80 et:
-->