Skip to content

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:

json
{
  "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:

bash
# 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:

bash
npx lingo.dev@latest i18n

This automatically:

  1. Reads your source PHP files
  2. Identifies new or modified strings
  3. Translates only what's changed
  4. Creates or updates target language files with proper PHP syntax

Smart PHP Array Handling

Nested Structure Support

Lingo.dev preserves complex array hierarchies:

php
<?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
<?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:

json
"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:

json
"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

  1. Framework Compatibility: Works seamlessly with Laravel's localization system
  2. Structure Preservation: Maintains exact PHP array syntax and nesting
  3. Context-Aware: AI understands application context for better translations
  4. Incremental Updates: Only translates what's changed, saving time and resources
  5. Format Flexibility: Handles both simple and complex translation structures

Best Practices

Key Organization

Group related translations under common parent keys:

php
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 replacements
  • for 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.