Module Language

Each module can have separate language files to prevent messing up with the system language files.

To add language files to your module so users can translate it, you must create a folder in modules/[module_name]/language/[language_name_folder]

At this time the [language_name_folder] must exist in the core language files located in application/language

For example, if you want to create English language translations, you will create the following folder(s): /modules/[module_name]/language/

Language Files

In each language, you can create unlimited number of files e.q. if you want to separate specific features language files or you can include them in one general language file.

The file name must end with _lang.php, you should check the Codeigniter framework documentation for more info about the language file name and it’s usage.

In this example we will create sample_module_lang.php file in /modules/[module_name]/language/english/

For each additional language you want to have translations, you must include all files from your general language e.q. in this case English

For example, if you have 3 language files in the / folder and you want to include new Spanish language, you must create new folder for the Spanish language and copy those 3 language files in the / folder.

Registering Language Files

Instead of loading the language files directly there is a helper function to register the language files and allow your language to support using a custom_lang.php file so the end users can overwrite the translations.

More info about custom_lang.php file in the language directory can be found here

In your module init file add the following code:

register_language_files('module_name', ['sample_module']);

The first parameter to the register_language_files function is the module name, don’t forget to replace module_name with your actual module name.

The second parameter must be an array with language files names without the _lang.php.

Fetching a Line of Text

Instead of using the Codeigniter framework default method to fetch translation line of text, you can use Daedelix PSA custom function:

/**
 * @param  string $line   language line key
 * @param  mixed $label   label e.q. if you have $lang['sample_module_create_new'] = 'Create New %s';
 * @return string         language text
 */
_l($line, $label = '', $log_errors = true);

Conflicts

Make sure that your language keys you add in the language files do not conflict with Daedelix PSA language keys that are added in application/language or with any other modules.

For this reason, we recommend to add unique language keys or prefix them with your module name.

Did you find this article useful?

  • Introduction to modules

    The modules documentation is valid starting from version 1.2.3.2 Daedelix PSA version 1.2.3.0 comes ...
  • Module Basics

    The modules documentation is valid starting from version 2.3.2 Daedelix PSA modules use the Code...
  • Module File Headers

    Each module in Daedelix PSA consist of init file which contains the general module configuration an...
  • Create Menu Items

    If you are creating your custom modules, probably you will want to create menu items that will be s...
  • Common Module Functions

    register_activation_hook /** * Register module activation hook * @param string $module module s...