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:

  • Meta information.
    These messages are kept in the meta.xml file in the extension's root directory. To provide a translation of a node, specify the same node with a certain xml:lang attribute with a 4-letter language code conforming to RFC1766. For example:
<description>Easily add customers and websites</description>
<description  xml:lang="de-DE">Einfache Neukundenerfassung & simple Website-Erstellung</description>
  • Other messages.
    These messages are a part of the extension code, for example, form input captions, page titles, action names, etc. Next in this chapter you will learn how to help the system discover the translations to display them to Plesk users.

 

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(
    '<em>acceptButtonText</em>' => '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(
    '<em>acceptButtonText</em>' => 'Accept',
    '<em>cancelButtonText</em>' => 'Cancel',
);

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

<?php

$messages = array(
    '<em>acceptButtonText</em>' => 'Accept',
    '<em>cancelButtonText</em>' => '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',
);
 

Leave your comments on this page

Leave your feedback or question on this documentation topic below. For technical assistance, contact your hosting service provider or submit a request to Plesk support. Suggest new features for Plesk here. Discuss general questions on the Plesk forum. All offtopic comments will be removed.