Basic Usage
Constructor
The
locale object constructor is
get_handle(), rather than
new().
get_handle() is an argument-based singleton.
get_handle() does not require you to pass arguments to it, because it determines the appropriate information based on the user calling the function.
my $locale = Cpanel::Locale->get_handle();
Generally, in modules and large scripts that may or may not need a locale object, you should use:
package XYZ;
my $locale;
sub something_that_needs_to_say_seomthing_to_the_end_user {
$locale ||= Cpanel::Locale->get_handle();
print $locale->maketext('All your base are belong to us');
}
Main Method
The
maketext() function is the main method for constructing
locales. The function takes the phrase, or
lexicon key, as its first argument. Any other arguments are used for the string's
bracket notation.
print $locale->maketext('Hello World');
print $locale->maketext('My name is [_1]',$name);
Remember: Do
not use any markup in your phrase. For more information about consistency and common conventions, visit our documentation
here.
Other Methods
-
encoding() — This function returns the character set of the locale's lexicon data.
-
datetime() — This function returns a string that contains localized date and time data.
- This function is a bracket notation method that you can use directly if all you want to output is a localized date and time.
Topic revision: r3 - 01 Oct 2009 - 19:40:00 - Main.JustinSchaefer
CpanelLocale.BasicUsage moved from Sandbox.BasicUsage on 01 Oct 2009 - 19:40 by Main.JustinSchaefer -
put it back