Localization

The system automatically displays extension messages in the language which Plesk currently uses if the extension has the corresponding translations. For example, if a customer uses the web interface in German, the extension also has the option to display its messages in German.

Extension messages are categorized into the following groups:

<description>Easily add customers and websites</description>
<description  xml:lang="de-DE">Einfache Neukundenerfassung & simple Website-Erstellung</description>

 

The interface that allows for automatic message translation is called pm_Locale and it is presented by the corresponding class. To use this interface, you need:

  1. Design the placeholders (keys) you will use instead of actual values in the GUI messages. For example, to substitute a button caption Accept, you may use acceptButtonText. A key can be an arbitrary string.
  2. Use pm_Locale::lmsg(key) instead of an actual string in the extension code. Here key can be acceptButtonText we obtained at step 1.
  3. Add language-dependent values for each key.

The key-value pairs must be included in the $messages associative array, for example:

<?php

$messages = array(
    'acceptButtonText' => 'Accept',
);

A file which includes the $messages array must reside in <product-root>/plib/modules/<module ID>/resources/locales/ and its name must be equal to the corresponding 4-letter locale code. For example: de-DE.php. All messages corresponding to a certain language must be stored in a language-specific file. For example,

<product-root>/plib/modules/<module ID>/resources/locales/en-US.php:

<?php

$messages = array(
    'acceptButtonText' => 'Accept',
    'cancelButtonText' => 'Cancel',
);

<product-root>/plib/modules/<module ID>/resources/locales/de-DE.php:

<?php

$messages = array(
    'acceptButtonText' => 'Accept',
    'cancelButtonText' => 'Stornieren',
);

To retrieve the currently used interface language, you can use the getCode method.

The following example shows the contents of an English locale file for a module with the code panel-news, which is located in the file /usr/local/psa/admin/plib/modules/panel-news/resources/locales/en-US.php.

<?php
     
$messages = array(
    'blockTitle' => 'Plesk News',
    'buttonTitle' => 'View Article',
);