Laravel: What's wrong with my PHP translation files?

BabelEdit can only read simple PHP translation files with a specific structure. It does not support complex PHP code or logic in these files.

Supported format requirements:

  • The file must contain exactly one return statement, with no other PHP code.
  • The return value must be an array.
  • Array keys and values must be string literals ("key" => "value").
  • Nested arrays are allowed (see example below).

✅ Example of a valid translation file:

<?php
return [
    "app_name" => "Example",
    "greeting" => "Hello world!",
    "common" => [
        "dateranges" => [
            "custom" => "Custom",
            "last_7d" => "Last 7 days",
            "last_28d" => "Last 28 days"
        ]
    ]
];

❌ Example of unsupported PHP code:

<?php
declare(strict_types=1)              // ERROR: Extra code not allowed
return [
    "app_name" => appName(),         // ERROR: Functions not allowed
    "greeting" => "Hello " . $p,     // ERROR: Variables not allowed
    "common" => [
        "dateranges" => [
            "custom" => "Custom",
            7 => "Last 7 days",      // ERROR: Keys must be strings
            28 => "Last 28 days"
        ]
    ]
];

Typical error messages:

  • Only a single return statement is allowed in the translation file.
  • Translation id must be a string literal
  • Translation for id 'name' must be a string literal