laravel-lang/publisher
Developer tool for Laravel Lang: publish and manage translation files in your Laravel app. Installs via Composer and provides commands to pull package locales into your project so you can customize and keep language resources up to date.
Installation
composer require --dev laravel-lang/publisher
Ensure your Laravel version (10–13) is supported (check releases).
Publish Config
php artisan vendor:publish --provider="LaravelLang\Publisher\PublisherServiceProvider"
This creates config/publisher.php with default settings (e.g., locales, default_locale, smart_punctuation).
Publish Translations
php artisan lang:publish
auth.php, validation.php) to resources/lang/{locale}/.force_overwrite).Verify
Check resources/lang/ for new locale folders (e.g., en, fr, es). Test with:
__('validation.required', [], 'es'); // Should return Spanish validation message
// config/publisher.php
'locales' => [
'en', 'es', 'fr', 'de', // Add your locales
],
php artisan lang:publish
// config/app.php
'locale' => 'es',
config/publisher.php for customization (e.g., ignore_files, smart_punctuation per locale).resources/lang/ to inspect published files and manual overrides.Initial Setup
php artisan lang:publish --locales=es,fr --force
--locales: Target specific locales (comma-separated).--force: Overwrite existing files (use cautiously).Incremental Updates
php artisan lang:update
Selective Publishing
php artisan lang:publish --files=auth,validation
auth.php, validation.php).php artisan lang:remove --locales=it
it locale folder and all its files.GitHub Actions Example (.github/workflows/locales.yml):
name: Sync Locales
on:
schedule:
- cron: '0 0 * * 0' # Weekly sync
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-php@v3
with:
php-version: '8.2'
- run: composer install --dev
- run: php artisan lang:update --locales=es,fr
- run: git config --global user.name "CI Bot"
- run: git config --global user.email "ci@example.com"
- run: git add resources/lang/
- run: git commit -m "chore: sync translations" || echo "No changes"
- run: git push
--dry-run first to preview changes:
php artisan lang:update --dry-run
resources/lang/{locale}/ files manually. Publisher respects local overrides during updates.custom.php) in resources/lang/{locale}/ and exclude them from publishing:
// config/publisher.php
'ignore_files' => ['custom.php'],
Enable for French/other locales:
// config/publisher.php
'smart_punctuation' => [
'fr' => true,
'es' => false,
],
") with curly quotes (“ ”) for locales that require it.// app/Http/Middleware/SetLocale.php
public function handle($request, Closure $next) {
App::setLocale($request->header('Accept-Language') ?? config('app.fallback_locale'));
return $next($request);
}
config/app.php:
'fallback_locales' => ['es' => ['en'], 'fr' => ['en']],
use LaravelLang\Publisher\Facades\Publisher;
public function test_translation() {
Publisher::fake(); // Override translations for testing
Publisher::shouldReturn('Hello', 'test.key');
$this->assertEquals('Hello', __('test.key'));
}
public function test_french_validation() {
$response = $this->withHeader('Accept-Language', 'fr')
->post('/register', ['name' => '']);
$response->assertSessionHasErrors('name', 'Le champ nom est requis.');
}
config/publisher.php in a shared package.--files to sync only changed modules:
php artisan lang:update --files=auth,pagination --locales=es
File Conflicts
--force sparingly. Prefer manual merges or:
php artisan lang:update --dry-run # Preview changes first
git diff to compare local vs. upstream files before updating.Locale-Specific Quirks
'smart_punctuation' => ['fr' => ['except' => ['*.php']]],
Circular Dependencies
auth.php includes validation.php which includes auth.php).--no-deep-merge flag (if available in future versions).Case Sensitivity
Auth.php vs. auth.php).ignore_files or use .gitattributes:
resources/lang/* text=auto eol=lf
Lumen Support
lang_path() may not be autoloaded in Lumen.bootstrap/app.php:
$app->withFacades();
if (! function_exists('lang_path')) {
function lang_path() {
return __DIR__.'/../resources/lang';
}
}
Verbose Output
php artisan lang:publish --verbose
Log File Conflicts
Enable logging in config/publisher.php:
'log_conflicts' => true,
storage/logs/publisher.log.Checksum Mismatches
chmod -R 755 resources/lang/
.env Overrides
.env:
PUBLISHER_LOCALES=es,fr
PUBLISHER_FORCE_OVERWRITE=false
Project Name Detection
How can I help you explore Laravel packages today?