Language translation files are placed inside the appropriate language languages directory within a widget.


Note: Plugin language files contain data for both the front-end and administrative back-end.


As previously mentioned, language files are setup as key/value pairs. A key is used within the plugin's code and the translator retrieves the associated string for the given language. The following code is an extract from a typical plugin language file.

; Plugin - System - Test (en-US)

Translation keys can be upper or lowercase or a mix of the two and may contain underscores but no spaces. HUBzero convention is to have keys all uppercase with words separated by underscores, following a pattern of PLG_{PluginGroup}_{PluginName}_{Text} for naming. Adhering to this naming convention is not required but is strongly recommended as it can help avoid potential translation collisions.

See the Languages overview for details.


The appropriate language file for a plugin is not preloaded when the plugin is instantiated as many plugins may not have language files at all. As such, one must specifically load any file(s) if they are needed. This can be done by setting the $_autoloadLanguage property to true or by manually loading the desired language files by calling the loadLanguage() method. This method accepts the name of the plugin (e.g., plg_{PluginGroup}_{PluginName}) and an optional base path to start from (e.g., PATH_APP, PATH_CORE).

// No direct access
defined('_HZEXEC_') or die();

class plgSystemTest extends Hubzero\Plugin\Plugin
	 * Affects constructor behavior. If true, language files will be loaded automatically.
	 * @var  boolean
	protected $_autoloadLanguage = true;

Note that the string passed to the loadLanguage() method matches the pattern for the naming of the language file itself, minus the language prefix and file extension.

Translating Text

Below is an example of accessing the translate helper:

<p><?php echo Lang::txt("PLGN_EXAMPLE_MY_LINE"); ?></p>

Strings or keys not found in the current translation file will output as is.

See the Languages overview for details.

Last modified:

  • Copyright © 2022 Hubzero
  • Powered by Hubzero®