Localization-files overview

Brief explanation of Language files to get started

In a default installation of Cotonti, all text is displayed in English. This is common known, but not always suitable for your site.

Those texts can be change via the language files.

There are already localization available for Cotonti. See http://www.cotonti.com/locales/.

Versions of core language files can slighly differ from version to version, so be sure to download proper one. If you can not find your version just try to download file for previous version or use special service to localize it to your language (see special page with instructions).

Cotonti uses as localization files PHP-defined plain array files (see details below).

#1. Language code

Each language has his own 2-character ISO language code. eg. English: en ; Russian: ru ; German: de ; Dutch: nl ; …
This language code is used in each language-file. eg. `xxxx.en.lang.php`, `xxxx.ru.lang.php`, ...


#2. Locations of the language files

There are different kind of language files which are located in different folders. Here are description of main language files used by Cotonti. In the list below you can substitute lang_code with a 2-character ISO code of an actual language.

/lang    This folder contains common and core language files. Each language has its own directory named as its language code eg. /lang/en/
/lang/lang_code/admin.lang_code.lang.php   administration backend localization
/lang/lang_code/countries.lang_code.lang.php   localized country names
/lang/lang_code/main.lang_code.lang.php   common lexis
/lang/lang_code/message.lang_code.lang.php   localized service messages
/lang/lang_code/translit.lang_code.lang.php   for languages other than English, it may represent tables for forward and backward transliteration
/lang/lang_code/users.lang_code.lang.php   user account related language strings
/modules/ext_name/lang/ext_name.lang_code.lang.php   contains extension localization (language) files
/plugins/plugin_name/lang/plugin_name.lang_code.lang.php   contains plugin localization (language) files
/themes/theme_name/theme_name.lang_code.lang.php   contains theme localization (language) files
/images/smilies/lang/lang_code.lang.js   contains names for the smilies


#3. Content of the language files

Lets inspect `main.en.lang.php` for example:

 * English Language File (main.lang.php)
 * @package Cotonti
 * @copyright (c) Cotonti Team
 * @license https://github.com/Cotonti/Cotonti/blob/master/License.txt

defined('COT_CODE') or die('Wrong URL.');

 * Main strings
$L['Access'] = 'Access';
$L['Action'] = 'Action';
$L['Active'] = 'Active';
$L['Activity'] = 'Activity';

 * cot_declension data
$Ls['Guests'] = 'guests, guest';

As noted before, for localization Cotonti use common PHP files with arrays of localizatio strings. Since 0.9.13 version it's strictly recommended to use only plain arrays (see technical details here).

First part is general info about the file. Package name, copyrigt, etc.
Below `defined('COT_CODE') or die('Wrong URL.');` you can find the language strings.

Strings is defined in plain arrays in `key => value` format.

Key identifier is a string ID of localization record and should be same across all (country specific) language files.  It's used to access certain language record from PHP code or template files (*.tpl) e.g. {PHP.L.Access} (see detailed info about accessing language data from templated here). This string in the tpl will be replaced by the corresponding value  ('Access' in our example).
Cotonti language files is also allow to define plural forms for some strings — see $Ls array record. It utilized by `cot_declension()` function and either can be used both in PHP code or Template files.


#4. Changing the language of your site

There are 2 ways to change the language used at the site.

  • сhange the language in the users own profile. This will effect only the user that changed his language;
  • сhange the default language in datas/config.php:

$cfg['defaultlang'] = 'en';                      // Default language code

This will change the language for all guests and all new registered users.
There is also a setting in admin-menu to force the default language for all users (Administration panel → Configuration → Locale). 

#5. Creating your own localization

In two words, to localize something to your language it needs to create language file(s) for your own:

  • copy all language files and change the 2-character ISO code to the language you will use (For the location of the files, see above);
  • translate all texts after “=” sign (values of an arrays ). Don’t change keys of an array or the text before “=”, or the strings will become unusable.

if you are full of power to start translating some thing to your language — it's a good practice to do it public, so Cotonti community can use it or even help you with it.

  • if you plan to translate Cotonti core language files you can use Transifex project (see details). 
  • if you plan to localize some extension, look if it available as GitHub repository from plugin author. If so, you can fork repo, translate necessary files and suppose your translation as a PR (pull request) to be applied to original extension.

No comments yet
Only registered users can post new comments