Interface Text

From Cloudrexx Development Wiki
Jump to: navigation, search

Introduction

Contrexx is a multilingual software. All interface text is localized to the user's selected language. This must be taken into account when developing new extensions to Contrexx. Interface text must therefore not be placed hard-coded (in a specific language) to the presentation layer. Instead of placing hard-coded text into the presentation layer, so called text-variables must be used.

Text-Variable

A text-variable refers to a certain element of the global array $_ARRAYLANG.

Scheme

The scheme of a text-variable is as follow:

TXT_<COMPOMENT_NAME>_<SHORT_AND_CONCISE_DESCRIPTION_OF_TEXT>

Whereas <COMPOMENT_NAME> is the name, in uppercase, of the compoment (module) the text-variable is in use (i.e. NEWS, SHOP) and <SHORT_AND_CONCISE_DESCRIPTION_OF_TEXT> should be a short and concise description of the text itself. The text-variable is written in USU-Notation according to the Naming conventions of Contrexx.

Example
$_ARRAYLANG['TXT_NEWS_ADD_MESSAGE'] = "Add new message";

Organization

All text-variables of a certain compoment (module) must be placed in the module's language folder (/lang). I.e. for the news module, all text-variables (interface text) are located in the folder core_modules/news/lang.

Furthermore, the text-variables of the frontend are separated from those of the backend. Text-variables' of the frontend are to be put in the file frontend.php and those of the backend into the file backend.php.

The interface text (files frontend.php / backend.php) of a certain language must then be put into a separate folder in the module's language folder, where the language's ISO 639-1 code is used as the folder's name.

I.e. the English interface text of the news module is located in core_modules/news/lang/en/.

The content of a module's language folder would in general look like the following:

lang
├── de
│   ├── backend.php
│   └── frontend.php
├── dk
│   ├── backend.php
│   └── frontend.php
├── en
│   ├── backend.php
│   └── frontend.php
├── fr
│   ├── backend.php
│   └── frontend.php
├── it
│   ├── backend.php
│   └── frontend.php
└── ru
    ├── backend.php
    └── frontend.php

Fallback / Base

Whenever a specific localized version of a text-variable can't be loaded (due to it's missing definition), it's English localization is used as a fallback. Therefore, every text-variable must at least be localized in English (lang/en/frontend.php or lang/en/backend.php).

Load Text-Variables

The Text-Variables (lang/*) of the requested module are automatically loaded by InitCMS.

This can also be done manually, for instance if you need the Text-Variables of a module that provides a functionality to be included in the layout, whereas the module itself is not being loaded in such a case (section is not set to the module in question): <highlightsyntax>// load text-variables of module calendar global $objInit; $langData = $objInit->loadLanguageData('calendar');

// optionally push the manually loaded text-variables into the global text-variable container $_ARRAYLANG global $_ARRAYLANG; $_ARRAYLANG = array_merge($_ARRAYLANG, $langData);</highlightsyntax>

Usage

Let's assume we have the following template: <highlightsyntax>... some html-code ... {TXT_NEWS_OVERVIEW} ... </highlightsyntax>

This template contains the text-variable TXT_NEWS_OVERVIEW. This text-variable is subject to the module news, due to the module part (NEWS) of its name.

The selection of the correct localized version of a text-variable is done automatically by Contrexx. To output the correct interface text we would now do the following: <highlightsyntax>// Initialize template system // i.e.: $absolute_path_to_template_file -> ASCMS_CORE_MODULE_PATH.'/news/template' $objTemplate = new \Cx\Core\Html\Sigma($absolute_path_to_module_s_template_folder);

// Load view (template file) // i.e.: $filename_of_template -> 'module_news_overview.html' $objTemplate->loadTemplatefile($filename_of_template);

// Set interface text $objTemplate->setVariable('TXT_NEWS_OVERVIEW', $_ARRAYLANG['TXT_NEWS_OVERVIEW']);

</highlightsyntax>

Depending on the user's selected language, this will now output the localized version of the text-variable TXT_NEWS_OVERVIEW.