PHP Translation
Lingo.dev supports translating PHP language files used by Laravel framework.
Setting Up
First, make sure you've got a i18n.json
config file in your project root. Here's an example:
{
"version": 1,
"locale": {
"source": "en",
"targets": ["es", "fr", "de"]
},
"buckets": {
"json": {
"include": ["lang/[locale]/messages.php"]
}
}
}
This config tells Lingo.dev:
- Your source language is English;
- You want to translate to Spanish, French, and German;
- Your PHP files are in the
lang
folder, each file is namedmessages.php
and is inside its own locale folder (e.g.,lang/en/messages.php
)
Available Languages
Lingo.dev supports a wide range of languages. To see what's available:
npx lingo.dev@latest show locale sources # List available source languages
npx lingo.dev@latest show locale targets # List available target languages
Use these to pick the right locale codes for your project.
Translating
With your config set, run:
npx lingo.dev@latest i18n
Lingo.dev will:
- Read your source PHP file (e.g.,
lang/en/messages.php
); - Identify new or changed strings;
- Translate them to your target languages;
- Update or create the target PHP files (e.g.,
lang/es/messages.php
,lang/fr/messages.php
,lang/de/messages.php
).
Why This Works
Lingo.dev's approach is effective because:
- It respects your existing file structure, fitting into your workflow instead of forcing you to change it;
- It uses AI to understand context, giving you more accurate translations than traditional word-for-word methods;
- It's incremental, only translating what's new or changed, saving time and processing power.
Pro Tips
Nested Structures: Lingo.dev handles nested PHP arrays like a champ. Your complex i18n structures are safe.
json<?php return [ "nav" => [ "home" => "Home", "about" => [ "team" => "Our Team", "mission" => "Our Mission" ] ] ]
Pluralization: Many i18n frameworks use special syntax for pluralization and placeholders. Lingo.dev understands these:
json<?php return array( "items" => array( "one" => "{{count}} item", "other" => "{{count}} items" ) )
File Exclusions: You can exclude specific files from translation. This is useful for files that shouldn't be translated, for whatever reason:
json{ "buckets": { "json": { "include": ["lang/[locale]/*.php"], "exclude": ["lang/[locale]/my-file.php"] } } }
This setup will translate all PHP files in the
lang/[locale]
directory, except for files namedmy-file.php
.Multiple File Types: You can configure multiple file types in your
i18n.json
:json{ "buckets": { "php": { "include": ["lang/[locale]/messages.php"] }, "json": { "include": ["lang/[locale].json"] } } }
This configuration allows Lingo.dev to handle both PHP and JSON files in your project making it follow the default Laravel project structure.
By leveraging these features, you can maintain a robust, scalable i18n setup for your PHP Laravel project or any other frameworks that support the same format defined as PHP arrays. Lingo.dev's flexibility in handling different file structures and types makes it a powerful tool for managing translations in complex projects.