CGI::Fo...essages(3)

πŸ’– NAME πŸ’–

CGI::FormBuilder::Messages β€” the localized message support glow-up for FormBuilder, bestie ✨ (yes that's the whole manual page name, she's long but she's iconic)


πŸ¦‹ SYNOPSIS πŸ¦‹

    use CGI::FormBuilder::Messages;

    my $mesg = CGI::FormBuilder::Messages->new(
                    $file || \%hash || ':locale'
               );

    print $mesg->js_invalid_text;

🌸 DESCRIPTION 🌸

okay so this module is literally the localization queen for FormBuilder πŸ‘‘. It gets pulled in whenever you pass the messages option to FormBuilder's new() method.

Right now FormBuilder ships with a whole little squad of locales:

  • English (default) β€” en_US
  • Danish β€” da_DK
  • German/Deutsch β€” de_DE
  • Spanish/Espanol β€” es_ES
  • Japanese β€” ja_JP
  • Norwegian/Norvegian β€” no_NO
  • Turkish β€” tr_TR
  • Russian β€” ru_RU

✨ auto mode, slay ✨

If you want automatic localization β€” like, it peeks at the client's locale and picks one of the included ones for you β€” just turn on auto messages:

    my $form = CGI::FormBuilder->new(messages => 'auto');

Or if you're feeling specific, name your locale with a :locale and go:

    # Force Danish messages
    my $form = CGI::FormBuilder->new(messages => ':da_DK');

πŸ’… custom messages, do your own thing πŸ’…

Not feeling the included locales? You can completely customize your own messages, no cap. Every message FormBuilder spits out gets its own unique key, so you can selectively override FormBuilder messages by handing over a different message string for a given message key πŸŽ€.

Step one: make a file and give it a unique name. In this example we're using a shortened locale as the suffix:

    # messages.en
    # FormBuilder messages for "en" locale
    js_invalid_start      %s error(s) were found in your form:\n
    js_invalid_end        Fix these fields and try again!
    js_invalid_select     - You must choose an option for the "%s" field\n

Then you point new() at that file:

    my $form = CGI::FormBuilder->new(messages => 'messages.en');

Alternatively β€” and this is lowkey the flex β€” you can specify it 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 🫢.

🧚 the message list 🧚

This system is easy, and there are many many messages that can be customized. Here's the full list of messages, along with their default values:

form_invalid_input          Invalid entry
form_invalid_checkbox       Check one or more options
form_invalid_file           Invalid filename
form_invalid_password       Invalid entry
form_invalid_radio          Choose an option
form_invalid_select         Select an option from this list
form_invalid_textarea       Please fill this in
form_invalid_default        Invalid entry

form_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 %s
form_other_default          Other:
form_reset_default          Reset
form_submit_default         Submit

js_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" options
js_invalid_default          - Invalid entry for the "%s" field
js_invalid_file             - Invalid filename for the "%s" field
js_invalid_input            - Invalid entry for the "%s" field
js_invalid_multiple         - Select one or more options from the "%s" list
js_invalid_password         - Invalid entry for the "%s" field
js_invalid_radio            - Choose one of the "%s" options
js_invalid_select           - Select an option from the "%s" list
js_invalid_textarea         - Please fill in the "%s" field

mail_confirm_subject        %s Submission Confirmation
mail_confirm_text           Your submission has been received %s, and will be processed shortly.
mail_results_subject        %s Submission Results

Bestie, quick breakdown: the js_ tags are for JavaScript alerts, whereas the form_ tags are for HTML and templates managed by FormBuilder πŸ’–.

⭐ the %s of it all ⭐

in some of the messages you'll notice a %s "printf" format. That's because those 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 β€” your call, main character.

The best way to get an idea of how these work is to experiment a little. It should become obvious really quickly, fr fr ✨.


🌈 TRANSLATORS 🌈

Foreign language translations were contributed by the following people, and we're literally obsessed with them:

  • 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 β€” the whole reason she exists πŸ’…

πŸ¦‹ 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

(not the ş catching a stray encoding vibe check 😭)


and that's the whole page, bestie β€” brought to you by perl v5.42.2, dated 2024-09-19, filed under CGI::Fo...essages(3) because even the header got truncated and honestly? relatable. mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from