Translate Laravel PHP Language Files
Simplify localization for Laravel applications with Lingo.dev's native support for PHP language files - perfect for maintaining translations in the Laravel framework standard format.
Quick Setup
Create an i18n.json
configuration file in your project root:
{
"version": 1,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"php": {
"include": ["lang/[locale]/messages.php"]
}
}
}
This configuration:
- Sets English as your source language
- Targets Spanish, French, and German translations
- Works with Laravel's standard directory structure (
lang/en/messages.php
, etc.)
Find Supported Languages
Discover all available language options:
# View source language options
npx lingo.dev@latest show locale sources
# View target language options
npx lingo.dev@latest show locale targets
One Command Translation
Translate all your PHP language files with a single command:
npx lingo.dev@latest i18n
This automatically:
- Reads your source PHP files
- Identifies new or modified strings
- Translates only what's changed
- Creates or updates target language files with proper PHP syntax
Smart PHP Array Handling
Nested Structure Support
Lingo.dev preserves complex array hierarchies:
<?php
return [
"nav" => [
"home" => "Home",
"about" => [
"team" => "Our Team",
"mission" => "Our Mission"
]
]
];
All nested keys and values are properly translated while maintaining the exact structure.
Pluralization Support
Handles Laravel's pluralization syntax:
<?php
return [
"items" => [
"one" => "{{count}} item",
"other" => "{{count}} items"
]
];
Translations respect each language's pluralization rules while preserving placeholders.
Advanced Configuration Options
Exclude Specific Files
Keep certain files untranslated:
"php": {
"include": ["lang/[locale]/*.php"],
"exclude": ["lang/[locale]/config.php"]
}
Laravel's Mixed Format Support
Handle both PHP and JSON translation files in Laravel projects:
"buckets": {
"php": {
"include": ["lang/[locale]/*.php"]
},
"json": {
"include": ["lang/[locale].json"]
}
}
This matches the default Laravel project structure for complete localization support.
Why Laravel Developers Choose This Approach
- Framework Compatibility: Works seamlessly with Laravel's localization system
- Structure Preservation: Maintains exact PHP array syntax and nesting
- Context-Aware: AI understands application context for better translations
- Incremental Updates: Only translates what's changed, saving time and resources
- Format Flexibility: Handles both simple and complex translation structures
Best Practices
Key Organization
Group related translations under common parent keys:
return [
"auth" => [
"failed" => "These credentials do not match our records.",
"password" => "The provided password is incorrect.",
"throttle" => "Too many login attempts. Please try again in :seconds seconds."
]
];
Placeholder Protection
All Laravel placeholders are preserved exactly as they appear:
:name
,:count
,:value
for named replacementsfor template variables
{0}
and{1}
for positional replacements
By integrating Lingo.dev into your Laravel development workflow, you get powerful AI-driven translations while maintaining complete compatibility with Laravel's localization system.