🔥 CodeIgniter Intermediate

What is CodeIgniter 4's Language/Localization system?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

CodeIgniter 4's Language system provides internationalization (i18n) support. Create language files in app/Language/en/Messages.php: return ["welcome" => "Welcome, {0}!", "not_found" => "Page not found"]. Load language strings: $lang = service("language")->setLocale("fr"). Get a string: lang("Messages.welcome", ["Alice"]) — placeholders {0}, {1} are replaced with arguments. In views: <?= lang("Messages.welcome", [$username]) ?>. Auto-detect locale from browser: $request->negotiate->language(["en", "fr", "de"]). Store locale in session for user preference persistence. Language files can be nested: lang("Messages.validation.required"). CI4's language system is simpler than Laravel's but sufficient for most multi-language applications. For complex pluralization and number formatting, consider adding the intl PHP extension.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.