NAME
CGI::FormBuilder::Messages - Localized message support for FormBuilder
SYNOPSIS
use CGI::FormBuilder::Messages;my $mesg = CGI::FormBuilder::Messages->new($file || \%hash || ':locale');print $mesg->js_invalid_text;
DESCRIPTION
This module handles localization for FormBuilder. It is invoked by specifying the "messages" option to FormBuilder's new() method. Currently included with FormBuilder are several different locales:
English (default) en_USDanish da_DKGerman/Deutsch de_DESpanish/Espanol es_ESJapanese ja_JPNorwegian/Norvegian no_NOTurkish tr_TRRussian ru_RU
To enable automatic localization that will detect the client's locale and use one of these included locales, simply turn on "auto" messages:
my $form = CGI::FormBuilder->new(messages => 'auto');
Or, to use a specific locale, specify it as ":locale"
# Force Danish messagesmy $form = CGI::FormBuilder->new(messages => ':da_DK');
In addition to these included locales, you can completely customize your own messages. Each message that FormBuilder outputs is given a unique key. You can selectively override FormBuilder messages by specifying a different message string for a given message key.
To do so, first create a file and give it a unique name. In this example we will use a shortened locale as the suffix:
# messages.en# FormBuilder messages for "en" localejs_invalid_start %s error(s) were found in your form:\njs_invalid_end Fix these fields and try again!js_invalid_select - You must choose an option for the "%s" field\n
Then, specify this file to new().
my $form = CGI::FormBuilder->new(messages => 'messages.en');
Alternatively, you could specify this directly as a hashref:
my $form = CGI::FormBuilder->new(messages => {js_invalid_start => '%s error(s) were found in your form:\n',js_invalid_end => 'Fix these fields and try again!',js_invalid_select => '- Choose an option from the "%s" list\n',});
Although in practice this is rarely useful, unless you just want to tweak one or two things.
This system is easy, and there are many many messages that can be customized. Here is a list of messages, along with their default values:
form_invalid_input Invalid entryform_invalid_checkbox Check one or more optionsform_invalid_file Invalid filenameform_invalid_password Invalid entryform_invalid_radio Choose an optionform_invalid_select Select an option from this listform_invalid_textarea Please fill this inform_invalid_default Invalid entryform_invalid_text %s error(s) were encountered with your submission.Please correct the fields %shighlighted%s below.form_required_text Fields that are %shighlighted%s are required.form_confirm_text Success! Your submission has been received %s.form_select_default -select-form_grow_default Additional %sform_other_default Other:form_reset_default Resetform_submit_default Submitjs_noscript Please enable JavaScript or use a newer browser.js_invalid_start %s error(s) were encountered with your submission:js_invalid_end Please correct these fields and try again.js_invalid_checkbox - Check one or more of the "%s" optionsjs_invalid_default - Invalid entry for the "%s" fieldjs_invalid_file - Invalid filename for the "%s" fieldjs_invalid_input - Invalid entry for the "%s" fieldjs_invalid_multiple - Select one or more options from the "%s" listjs_invalid_password - Invalid entry for the "%s" fieldjs_invalid_radio - Choose one of the "%s" optionsjs_invalid_select - Select an option from the "%s" listjs_invalid_textarea - Please fill in the "%s" fieldmail_confirm_subject %s Submission Confirmationmail_confirm_text Your submission has been received %s, and will be processed shortly.mail_results_subject %s Submission Results
The "js_" tags are used in JavaScript alerts, whereas the "form_" tags are used in HTML and templates managed by FormBuilder.
In some of the messages, you will notice a %s "printf" format. This is because these messages will include certain details for you. For example, the "js_invalid_start" tag will print the number of errors if you include the %s format tag. Of course, this is optional, and you can leave it out.
The best way to get an idea of how these work is to experiment a little. It should become obvious really quickly.
TRANSLATORS
Foreign language translations were contributed by the following people:
- Danish translation (da_DK)
-
Jonas Smedegaard
- German translation (de_DE)
-
Thilo Planz
- Spanish translation (es_ES)
-
Florian Merges
- French translation (fr_FR)
-
Laurent Dami
- Japanese translation (ja_JP)
-
Toru Yamaguchi and Thilo Planz
- Norwegian translation (no_NO)
-
Steinar Fremme
- Turkish translation (tr_TR)
-
Recai Oktaş
Thanks!
SEE ALSO
CGI::FormBuilder
REVISION
$Id: Messages.pm 100 2007-03-02 18:13:13Z nwiger $
AUTHOR
Copyright (c) Nate Wiger <http://nateware.com>. All Rights Reserved.
This module is free software; you may copy this under the terms of the GNU General Public License, or the Artistic License, copies of which should have accompanied your Perl kit.
POD ERRORS
Hey! The above document had some coding errors, which are explained below:
- Around line 292:
-
Non-ASCII character seen before =encoding in 'Oktaş'. Assuming UTF-8