nixphp / i18n
NixPHP Internationalization Plugin
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:nixphp-plugin
Requires
- php: >=8.3
- nixphp/framework: dev-main
Requires (Dev)
- phpunit/php-code-coverage: ^12.1
- phpunit/phpunit: ^12.1
This package is auto-updated.
Last update: 2025-05-31 21:20:54 UTC
README
nixphp/i18n
Simple JSON-based translations for your NixPHP application.
This plugin provides a lightweight translation system for multilingual apps. It reads language files from disk, supports variable replacements, and falls back gracefully — all with minimal overhead.
🧩 Part of the official NixPHP plugin collection. Install it if you want clean, flexible localization without external libraries.
📦 Features
- ✅ Loads language files from
app/Resources/lang/
- ✅ Supports
translator()->get('key')
with fallback mechanism - ✅ Replaces variables via
:name
,:count
, etc. - ✅ Language codes follow ISO 639-1 (e.g.
en
,de
,fr
) - ✅ JSON-based – easy to edit, export and manage
📥 Installation
composer require nixphp/i18n
The plugin auto-registers and makes a translator()
helper available globally.
🚀 Usage
🔍 Get a translation
echo translator()->get('welcome');
Assuming app/Resources/lang/en.json
contains:
{ "welcome": "Welcome to our site!" }
You’ll see:
Welcome to our site!
✨ With replacements
echo translator()->get('greeting', ['name' => 'Flo']);
With this JSON entry:
{ "greeting": "Hello, :name!" }
Result:
Hello, Flo!
🌍 Switch language
translator()->setLocale('de');
Make sure app/Resources/lang/de.json
exists.
🔄 Fallback
If a key is missing, the key itself is returned:
translator()->get('unknown_key'); // → "unknown_key"
This helps you spot missing translations during development.
📁 File structure
app/
└── Resources/
└── lang/
├── en.json
├── de.json
└── fr.json
Each file should be a flat key-value map using UTF-8 encoded JSON.
✅ Requirements
nixphp/framework
>= 1.0- PHP >= 8.1
📄 License
MIT License.