Documentation

Languages

Setup

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

; Module - Hellow World (en-US)
COM_HELLOWORLD_LABEL_USER_COUNT = "User Count"
COM_HELLOWORLD_DESC_USER_COUNT = "The number of users to display"
COM_HELLOWORLD_RANDOM_USERS = "Random Users for Hello World"
COM_HELLOWORLD_USER_LABEL = "%s is a randomly selected user"

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 COM_{ComponentName}_{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.

Translating Text

Below is an example of accessing the translate helper:

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

Lang::txt is used for both simple strings and strings that require dynamic data passed to them for variable replacement.

<p><?php echo Lang::txt('Hello %s. How are you?', $name); ?></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®