Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Working with language translations

Table of Contents



Creating new languages

New languages can be added to AbanteCart as extensions from the marketplace or downloaded from AbanteCart.com Alternately, new languages can be created in the admin manually. This is done with creating new language in System -> Localization -> Languages. In this case, language can be translated using auto-translation mode in "Load missing language data" section. 
We recommend creating new language by creating new extension. Simplest process will be to copy any existing language extension, rename all files, replace flag icons and translate the text. Text can be translated using Google translator and manually verified and corrected.

Using Language translations in the code

AbanteCart using ALanguage class to handle all text translation. There is a global instance of ALanguage class always present in the registry for all controllers. Default language set from selected language [english.xml] is loaded for any run and available in any place. If any additional language sets are loaded they might override translation if same keys are used. Keep this in mind. To avoid overriding language text can be requested from specific section by specifying section at an argument to get() function. In controller, values can be accessed with function $this->language->get()


Code Block
languagephp
themeDJango
titleExample
$this->language->get('heading_title');  // Implicit call and gets last defined key text in the scope


Code Block
languagephp
themeDJango
titleor
$this->language->get('heading_title', 'catalog/product');  //explicit call to gets key text for given controller catalog/product


In the template (corresponding .tpl file) this value will be available in $heading_title
Each controller auto-loads corresponding language translation that is available for it. For instance, for controller catalog/product there will be catalog/product language set loaded automatically once the controller is loaded.
If you need more translation, you can load any other language set that will be used in controller and templates that are processed by given controller. Below are the examples how it is done:

Code Block
languagephp
themeDJango
titleExample
linenumberstrue
$this->load->language('catalog/category');
    //Get specific translation by key
$this->document->setTitle( $this->language->get('heading_title') );
    //Assign all translations to the template
    $this->view->batchAssign( $this->language->getAll() );


Code Block
languagephp
themeDJango
titleExample
$this->loadLanguage('catalog/category');
        //Get specific translation by key
$this->document->setTitle( $this->language->get('heading_title') );