get_language()
public function get_language(): string
Description
Retrieves the current application language. Checks multiple sources in order of priority:
- Session –
$_SESSION['app_lang'](set viaset_language()) - Cookie –
$_COOKIE['app_lang'](persistent across browser sessions) - Constant –
APP_LANGconstant (if defined in config) - Default – Falls back to
'en'(English)
This method is used internally by load() to determine which translation file to load.
Parameters
This method accepts no parameters.
Return Value
| Type | Description |
|---|---|
| string | The current language code (e.g., 'en', 'fr', 'es'). |
Example Usage
PHP
// Get current language
$current_lang = $this->language->get_language();
echo "Current language: " . $current_lang;
// Conditionally load content based on language
if ($this->language->get_language() === 'fr') {
// Load French content
$data['welcome'] = 'Bienvenue';
} else {
// Load English content
$data['welcome'] = 'Welcome';
}
// Use in validation error loading
$lang = $this->language->get_language();
$errors = $this->language->load("modules/validation/language/{$lang}/validation_errors.php");Notes
- The default language is
'en'(English). - To define a global default, set the
APP_LANGconstant in your configuration. - Session takes precedence over cookie, which allows users to temporarily override their saved language.