Translations
The LiveUser_Admin package allows you to manage translations of applications, areas, groups and rights to be used within LiveUser. It provides a series of methods to interact with the «liveuser_translations» table.
The example 1 provided with this PEAR package should help you starting quite quickly.
There are a few methods for translations management:
- addTranslation: to add a translation
- updateTranslation: to update a translation
- removeTranslation: to remove a translation
In this example, we'll consider translations for groups. We will then start by adding a group in the «liveuser_groups» table.
Next we'll add a translation for a group, update it, then list all groups with their translations before deleting the translation and the group.
Here is the full example :
Download «LUA_test_translations_group.php»
Additional examples of translations of applications, areas and rights are also available. However, as it follows the same principle, they are not explained in details here. Download:
- Download «LUA_test_translations_app.php»
- Download «LUA_test_translations_area.php»
- Download «LUA_test_translations_right.php»
Add a Group
First we'll add a group to the «liveuser_groups» table in order to test the translations.

Add a Translation (addTranslation)
function addTranslation($data)
Parameter(s)
This method takes 1 parameter: an array with a pair key/value of all fields in the «liveuser_translations»
- translation_id: an id
- section_type: a constant to specify whether the translation concerns an application, an area, a group or a right
- section_id: the id of the corresponding application (LIVEUSER_SECTION_APPLICATION), area (LIVEUSER_SECTION_AREA), group (LIVEUSER_SECTION_GROUP) or right (LIVEUSER_SECTION_RIGHT). See previous parameter
- language_id: the id of the language
- name: the name
- description: the description
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
To add a translation:
...
$translation_id = 5;
$section_id = 5;
$section_type = LIVEUSER_SECTION_GROUP;
$language_id = 'en';
$name = 'test';
$description = 'test group';
$data = array(
'translation_id' => $translation_id,
'section_id' => $section_id,
'section_type' => $section_type,
'language_id' => $language_id,
'name' => $name,
'description' => $description
);
$added = $LUA->perm->addTranslation($data);
...
This gives the following result:

Update a translation (updateTranslation)
function updateTranslation($data, $filter)
Parameter(s)
This method takes 2 parameters:
- an array with key/value containing the new value(s)
- an array with key/value to select the record to be updated
Attention: if no parameter is passed, all translations will be modified.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$new_translation = 'Another group name';
$translation_id = 5;
$data = array('description' => $new_translation);
$filters = array('translation_id' => $translation_id);
$updatetranslation = $LUA->perm->updateTranslation($data, $filters);
...
This gives the following result:

List groups
The function «getGroups» allows you to list all groups. If you request only fields from the «liveuser_groups» table, you will not see any translation.
Example
...
$params = array('fields' =>
array('group_id', 'group_define_name', 'is_active'));
$groups = $LUA->perm->getGroups($params);
...
This gives the following result:

To get the translation, add a field from the «liveuser_translations» table to the requested list of fields. You could then also add a «filters» array in order to select the language you want to have.
Example
...
$params = array('fields' =>
array('group_id', 'group_define_name', 'is_active', 'description'),
//'filters' => array('language_id' => 'en')
);
$groups = $LUA->perm->getGroups($params);
...
For the moment, we'll request translations in all languages. This gives the following result:

Remove a Translation (removeTranslation)
function removeTranslation($filter)
Parameter(s)
This method takes 1 parameter:
- an array with key/value to select the record(s) to be deleted.
Attention
- if no parameter is passed, all translations will be removed.
- deleting a translation does not delete the corresponding application, area, group or right
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$translation_id = 5;
$filter = array('translation_id' => $translation_id);
$removed = $LUA->perm->removeTranslation($filter);
...
This gives the following result:

Remove a Group
Finally we remove the group from the «liveuser_groups» table.

Getting Information on the last Error (getErrors)
function getErrors()
In case a function returns «false», it means that it has encountered a problem. You can get information on this error by calling this method.
Parameter(s)
This method takes no parameter.
Return value
This method returns:
- the error information
Example
...
$added = $LUA->perm->addTranslation($data);
if ($added === false)
{
echo 'Add_translation: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'Translation with id ' . $added . ' created';
}
...



