joomla/language
Joomla Framework Language package for internationalization and translations. Provides interfaces and utilities to manage language strings, load translation files, and integrate multilingual support in PHP 8.1+ applications (requires joomla/string).
Start by installing the package via Composer:
composer require joomla/language "~3.0"
The package is PHP 8.1+, requires the joomla/string package, and follows a traditional language-translation workflow. Create a Language instance with a base path and language code (e.g., en-GB), then use the Text class to translate keys. The simplest usage is:
use Joomla\Language\Language;
use Joomla\Language\Text;
$language = new Language('/path/to/app', 'en-GB');
$text = new Text($language);
echo $text->translate('COM_APP_HELLO');
Language files live in /path/to/app/language/en-GB/en-GB.ini, and keys must match ^[A-Z][A-Z0-9_.\-]*$.
LanguageFactory (ideally via DI container) to manage reusable Language and Text instances. Configure defaults (base path, default language) through a registry-like config.LanguageFactory::getLanguage() caches instances per language—useful for multi-language apps or per-request reuse.LocaliseInterface in xx-XX.localise.php to define language-specific behaviors (e.g., pluralization rules, transliteration). The factory auto-loads this when available.%s, %d) in .ini files and pass parameters via Text::translate('KEY', ['arg']).LanguageFactoryProvider and inject Text/Language into services using Container. This is critical for testability and modern app structure.Text::_(), Language::getInstance() etc.). Always instantiate with proper dependencies—testing requires mocking Language + Text together..ini files won’t match unless you extend MessageCatalogue. Debug with Language::debugFile() and check getErrorFiles().JPATH_ROOT). For unit tests, mount a temporary directory with test .ini files._QQ_ escape, Text::script(), and CMS-specific methods are gone. Re-implement JS string embedding or search helpers yourself.LocaliseInterface::getPluralSuffixes()—misconfiguring this breaks plural translations. Use en-GB\localise.php’s EnGBLocalise base class as a starting point for Western languages.Language and return stub MessageCatalogue instances; avoid loading real files in tests unless testing i18n loading itself.How can I help you explore Laravel packages today?