Languine supports PHP localization files using a modern array-based format. Perfect for PHP applications, it handles nested structures while maintaining type safety with strict types enabled.
First, create a languine.json
config file in your project root:
{ "locale": { "source": "en", "targets": ["es", "fr", "de"] }, "files": { "php": { "include": ["lang/[locale]/*.php"] } } }
Your PHP translation files should return an array. Here's an example structure:
<?php declare(strict_types=1); return [ 'welcome' => 'Welcome to our app', 'auth' => [ 'login' => 'Log in', 'register' => 'Register', 'forgot_password' => 'Forgot your password?' ], 'errors' => [ 'not_found' => 'Page not found', 'server_error' => 'Server error occurred' ] ];
declare(strict_types=1)
is completely optional and is only used to ensure type safety.
With your config set, run:
npx languine@latest translate
When you run this command, Languine will:
lang/en/*.php
)lang/sv/*.php
)