Use localization in Template Toolkit files to produce dynamic interfaces in multiple languages.
cPanel & WHM uses the locale system to localize phrases. For more information, read our Guide to Locales documentation.
Before you write text for localized user interfaces, we strongly recommend that you review our Best Practices documentation.
Localized phrases in Template Toolkit files use the following syntax:
[% locale.maketext('Your localized phrase goes here.') %]
The template passes everything between the single quotes (
'') through the locale system as a single localized phrase. To reuse phrases as often as possible, which significantly lowers translation costs, we recommend that you divide sentences into separate
locale.maketext calls whenever possible.
To pass variables into localized phrases, use the following syntax:
[% locale.maketext('The system set up your email address "[_1]" on your domain "[_2]".', email, domain) %]
This template code passes the phrase through the locale system, and then replaces the variables (
[_2]) with the variables' values (
email@example.com and the
domain value is
example.com, the template displays the following text, localized for the authenticated user:
The system set up your email address "firstname.lastname@example.org" on your domain "example.com".
For more information about variables in localized phrases, read CPAN's
To display different localized phrases based on a variable's value, use
[% IF country_name -%] [% locale.maketext('This computer's location appears to be: [_1] ([_2]).', country_name, country_code) %] [% ELSE -%] [% locale.maketext('The system failed to look up the IP address's geographical origin because of an error: [_1]', country_lookup_error) %] [% END -%]
IFcondition that displays a string if the
country_namevariable exists and has a value.
ELSEcondition that displays an alternate string if the first condition's requirements are not met.