PHP
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.
Setting Up
First, create a babely.json config file in your project root:
babely.json
{ "locale": { "source": "en", "targets": ["es", "fr", "de"] }, "files": { "php": { "include": ["lang/[locale]/*.php"] } } }
File Format
Your PHP translation files should return an array. Here's an example structure:
lang/en/common.php
<?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.
Translating
With your config set, run:
typescript
npx babely@latest translate
When you run this command, Languine will:
- ◇Parse your source PHP files (e.g.,
lang/en/*.php) - ◇Detect new or modified translation strings
- ◇Generate translations for target languages
- ◇Create or update target language PHP files (e.g.,
lang/sv/*.php) - ◇Preserve PHP structure and nesting
- ◇Maintain strict types declaration
- ◇Keep code formatting consistent