The Function getTranslation

In SmartWeb there is a function that allows access to user entered information on your website. This functionality is achieved through the use of the ‘getTranslation’ function. This is a global function that exists on all controllers and is used to get all user entered information like: product title, blog text and contact form information etc. This function can get data in all language translations, but it defaults to the current user selected language, in other words, the language the user is currently viewing the page in.

The ‘getTranslation’ function should not be confused with the $text variable which is also stores translations. The difference is what data you receive. getTranslation gets data input into the database, meaning all the products, blog or news entries you’ve made. While the $text variable is a list of general system texts, like areacode, username, buy button text etc.


getTranslation() Reference Table

The function takes 4 parameters. The table below, describes the function and the order of parameters.

Function controller->getTranslation(id, title, module, language)

Parameter Required Definition Example
id x Element id. 10
title x Refer to examples below. seo_title
module   (optional) Refer to examples below. product

(optional) ISO Language code e.g. Danish (DK), English (UK), Norway (NO) etc.

For more information: Refer to ‘Languages and Domains’ in the SmartWeb Administration.



When calling the function, there are a couple of things you should be aware of:

  1. The function knows about its module, but it can get texts from all modules within the system.
  2. The function knows about the language currently selected, but it can get texts from all languages within the system.


This example shows how the function and parameters are used to call user entered information with the use of controllers from the form.tpl file:

*CODE* *SNIPPIT* {$formController->getTranslation($formEntity->Id, "form-element", "button")}*CODE*


An important thing to remember is that controllers in the SmartWeb system are ‘self aware’, this means that controllers are able to use the two required parameters: id and title and still have access to the correct information because the controller knows all of the other relevant information, here is an example from the product-list.tpl file:

*CODE* *SNIPPIT* {$descriptionBottom = $userController->getTranslation($brand->Id, "text_two")}*CODE*


Of course you can also use all four parameters, this is helpful when you want to get translations for specific languages. e.g. displaying Product titles for the 'UK' (English) language.


Some controllers like: productController and blogController have shorthands that allow you to get access to use specific information easier, like so:

*CODE* *SNIPPIT* productController->getDescription productController->getDescriptionShort blogController->getDescription*CODE*