Module Labels
require_once 'include/utils.php';
$label = translate('LBL_KEY', 'Accounts');
Overview
Sugar, which is fully internationalized and localizable, differentiates languages with unique language keys. These keys prefix the files that correspond to particular languages. For example, the default language for the application is English (US), which is represented by the language key en_us. Any file that contains data specific to the English (US) language begins with the characters en_us. Language label keys that are not recognized will default to the English (US) version.
For more information on language keys, please refer to the Languages page.
Module Labels
$mod_strings
The module language strings are stored in $mod_strings
. This section explains how the $mod_strings
are compiled. All modules, whether out-of-box or custom, will have an initial set of language files in ./modules/<module>/language/<language key>.lang.php
.
As you work with the system and modify labels through Studio, changes to the labels are reflected in the corresponding module's custom extension directory: ./custom/Extension/modules/<module>/Ext/Language/<language key>.lang.php
.
Customizing Labels
If you are developing a customization and want to be able to create new or override existing label values, you will need to work within the extension modules directory. To do this, create ./custom/Extension/modules/<module>/Ext/Language/<language key>.<unique_name>.php.
The file should contain your override values with each label index set individually. An example of this is:
<?php
$mod_strings['LBL_KEY'] = 'My Display Label';
Once the file is created with your adjustments, navigate to Admin > Repair > Quick Rebuild & Repair. This will compile all of the Extension files from ./custom/Extension/modules/<module>/Ext/Language/
to ./custom/modules/<module>/Ext/Language/<language key>.lang.ext.php
.
Label Cache
The file locations discussed above are compiled into the cache directory, ./cache/modules/<module>/language/<language key>.lang.php
The cached results of these files make up each module's $mod_strings
definition.
Hierarchy Diagram
Retrieving Labels
There are two ways to retrieve a label. The first is to use the translate()
function found in include/utils.php
. This function will retrieve the label for the current user's language and can also be used to retrieve labels from $mod_strings
, $app_strings
, or app_list_strings
.
An example of this is:
require_once 'include/utils.php';
$label = translate('LBL_KEY', 'Accounts');
Alternatively, you can use the global variable $mod_strings
as follows:
global $mod_strings;
$label = '';
if (isset($mod_strings['LBL_KEY']))
{
$label = $mod_strings['LBL_KEY'];
}
Accessing Module Strings in Sidecar
All language-pack strings are accessible within the Sidecar framework.
$mod_strings
To access the $mod_strings
in Sidecar, use app.lang.get()
:
app.lang.get('LBL_NAME', 'Accounts');
To access the $mod_strings
in your browser's console, use SUGAR.App.lang.get()
:
SUGAR.App.lang.get('LBL_NAME', 'Accounts');
For more information, please refer to the app.lang.get section of the Languages page.