Optional capability module that extends forge kernel to have language capabilities, providing an easy-to-use localization system.
ForgeLanguage provides a complete localization system for Forge Kernel applications. It offers a convenient way to retrieve language-specific strings, manage available languages, and present a language switcher component to your users.
Install ForgeLanguage using ForgePackageManager.
# Install module
php forge.php package:install-module --module=ForgeLanguage
The module registers global helpers (located in modules/ForgeLanguage/src/Support/helpers.php)
that you can use anywhere in your application, especially in views.
languageTerm()Fetches a translated string for a given key.
<?= languageTerm('welcome', 'Welcome to Forge Kernel', ['name' => 'John']) ?>
current_language()Returns the current active language code (e.g., 'en', 'es').
<?php $current = current_language(); ?>
available_languages()Returns an array of available languages defined in your app.
<?php $languages = available_languages(); ?>
The module includes a ready-to-use Language Switcher component to let users easily swap languages. Use it directly in your views.
<?php
use App\Modules\ForgeLanguage\Definitions\LanguageSwitcherDefinition;
?>
<?= component(
name: 'ForgeLanguage:language-switcher',
props: [
'definition' => new LanguageSwitcherDefinition(
showFlags: true,
showLabels: true,
showCodes: false,
)
]
) ?>
To add new languages to your application, simply create a PHP file in your defined structure
language path, by default app/Languages/
directory. For example, for English create en.php, and for Spanish create es.php.
Each file should return an associative array of keys and their translations.
// app/Languages/en.php
<?php
return [
'welcome' => 'Welcome to Forge Kernel',
'description' => 'Welcome to your development playground'
];