bit-mx/statamic-translate-lang-files
Edit Laravel/Statamic language files from the Statamic Control Panel. Browse locales and lang groups, update keys, save back to lang/{locale}/*.php, sync missing keys from a reference locale, optionally refresh caches, invalidate OPcache, and auto-commit to Git.
composer require bit-mx/statamic-translate-lang-files
php artisan statamic-translate-lang-files:install
access translation-manager utilityedit translation managersync translation manager/cp/translate-lang-files).Edit a translation key for a specific locale:
es) and translation group (e.g., auth.php).failed).resources/lang/es/auth.php.sequenceDiagram
participant User
participant CP
participant Package
participant LangFiles
User->>CP: Navigate to Translation Manager
CP->>Package: Fetch locales/groups
Package->>LangFiles: Read `lang/{locale}/*.php`
User->>CP: Edit key/value
CP->>Package: Save changes
Package->>LangFiles: Write to disk
Package->>CP: Refresh cache (if enabled)
en).fr).en as the reference.// In EventServiceProvider
protected $listen = [
'translate-lang-files::syncing' => [
YourSyncListener::class,
],
];
// config/statamic-translate-lang-files.php
'features' => [
'refresh_caches' => true,
'invalidate_opcache' => env('APP_ENV') === 'production',
],
php artisan cache:clear
php artisan config:clear
'git' => [
'auto_commit' => true,
'commit_message' => 'Update translations',
],
lang/ files trigger a Git commit.php artisan vendor:publish --tag=statamic-translate-lang-files-views
resources/views/vendor/statamic-translate-lang-files/....public function boot()
{
event('translate-lang-files::syncing', function ($locale, $referenceLocale) {
// Custom logic (e.g., skip certain keys)
return ['key1' => 'value1'];
});
}
en:
php artisan translate-lang-files:sync --reference=en --locales=es,fr,de
composer test
$this->actingAs($user)
->get('/cp/translate-lang-files')
->assertSee('Translation Manager');
Permission Issues:
edit translation manager).statamic:permissions table or run:
php artisan statamic:permissions:list
Cache Stale Data:
php artisan cache:clear
php artisan view:clear
refresh_caches in config if debugging:
'features' => ['refresh_caches' => false],
OPcache Conflicts:
invalidate_opcache temporarily:
'features' => ['invalidate_opcache' => false],
php artisan opcache:restart
Git Auto-Commit Failures:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
storage/logs/laravel.log.Locale/Group Discovery:
lang/ files follow the expected structure:
resources/lang/
├── en/
│ ├── auth.php
│ └── validation.php
└── es/
└── auth.php
php artisan translate-lang-files:generate
Log Translation Events:
Add to config/statamic-translate-lang-files.php:
'debug' => [
'log_events' => true,
],
Check logs in storage/logs/laravel.log for sync/save events.
Validate File Permissions:
Ensure storage/framework/ and resources/lang/ are writable:
chmod -R 775 resources/lang/
chmod -R 775 storage/framework/
Test with a Fresh Install: Clone the project and test the package in isolation to rule out conflicts.
Custom Translation Sources:
Override the TranslateLangFilesService to support non-PHP files (e.g., JSON):
// app/Providers/TranslateLangFilesServiceProvider.php
public function register()
{
$this->app->bind('translate-lang-files', function () {
return new CustomTranslateLangFilesService();
});
}
Pre/Post-Save Hooks: Listen for events to add custom logic:
// app/Providers/EventServiceProvider.php
protected $listen = [
'translate-lang-files::saving' => [
CustomTranslationValidator::class,
],
'translate-lang-files::saved' => [
CustomTranslationLogger::class,
],
];
Bulk Operations: Extend the sync command to handle bulk updates:
// app/Console/Commands/SyncTranslations.php
public function handle()
{
$locales = ['es', 'fr', 'de'];
foreach ($locales as $locale) {
$this->call('translate-lang-files:sync', [
'--reference' => 'en',
'--locale' => $locale,
]);
}
}
Reference Locale:
lang/ (e.g., en/auth.php).File Encoding:
lang/ files use UTF-8 encoding to avoid character issues.Reserved Keys:
auth.failed) unless intentional.Large Projects:
invalidate_opcache for projects with >100MB lang/ files.'features' => [
'use_database' => true, // Custom extension
],
Concurrent Edits:
// app/Services/CustomTranslateLangFilesService.php
public function save($locale, $group, $data)
{
if (!file_exists(storage_path("locks/{$locale}-{$group}.lock"))) {
file_put_contents(storage_path("locks/{$locale}-{$group}.lock"), '');
// Save logic here
unlink(storage_path("locks/{$locale}-{$group}.lock
How can I help you explore Laravel packages today?