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:
These messages are kept in the
meta.xmlfile 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:
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:
- 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.
- Use pm_Locale::lmsg(key) instead of an actual string in the extension code. Here key can be acceptButtonText we obtained at step 1.
- Add language-dependent values for each key.
The key-value pairs must be included in the $messages associative array, for example:
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,
To retrieve the currently used interface language, you can use the
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