load()
public function load(string $path): array
Description
Loads a language‑specific file, typically containing translation arrays. The path can contain the placeholder {lang}, which is automatically replaced with the current language code (from get_language()).
This method is primarily used by the Validation module to load error messages in the appropriate language, but can be adapted for other translation needs.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $path | string | Path to the language file, relative to APPPATH. Use {lang} as a placeholder for the language code. |
Return Value
| Type | Description |
|---|---|
| array | An associative array of translation strings loaded from the file, or an empty array if the file doesn't exist. |
Example Usage
PHP
// Load validation error messages for current language
$errors = $this->language->load('modules/validation/language/{lang}/validation_errors.php');
// Returns array like ['required' => 'The {field} field is required.', ...]
// Load custom translation file
$translations = $this->language->load('modules/my_module/language/{lang}/ui.php');
// Manual path without placeholder (fixed language)
$french_errors = $this->language->load('modules/validation/language/fr/validation_errors.php');
// Usage in validation setup
public function init_validation() {
$error_messages = $this->language->load('modules/validation/language/{lang}/validation_errors.php');
// Use $error_messages to customize validation errors
}Notes
- The path is relative to
APPPATH(application root). - The file must return an array variable named
$validation_errors(convention from Validation module). - If the file doesn't exist, an empty array is returned (no error thrown).
- Use
{lang}placeholder for dynamic language loading; omit it for fixed‑language files.