Download the PHP package our-edu/laravel-translation-client without Composer
On this page you can find all versions of the php package our-edu/laravel-translation-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download our-edu/laravel-translation-client
More information about our-edu/laravel-translation-client
Files in our-edu/laravel-translation-client
Package laravel-translation-client
Short Description Laravel client package for consuming centralized translation service
License MIT
Informations about the package laravel-translation-client
Laravel Translation Client
A Laravel package for consuming centralized translation services. This package replaces Laravel's file-based translation loader with an API-based loader that fetches translations from a remote translation service.
Features
- API-based translations - Fetch translations from a centralized service
- Write translations - Push translations back to the service
- Multi-level caching - Memory, Laravel cache, and service-side caching
- Automatic updates - Translations update without redeployment
- Multi-tenant support - Per-tenant translation isolation
- Zero code changes - Works with existing
trans()and__()calls - High performance - Sub-millisecond translation lookups
- Graceful degradation - Falls back to stale cache on API failures
- Import from files - Migrate existing Laravel translations
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
Installation
1. Install via Composer
2. Publish Configuration
This will create config/translation-client.php.
3. Configure Environment
Add the following to your .env file:
4. Configure Available Locales
In config/translation-client.php, add:
Configuration
All configuration options are in config/translation-client.php:
Usage
Basic Usage
Once installed, use Laravel's translation functions as normal:
Commands
Clear Cache
Clear translation caches:
Import Translations
Import translations from Laravel lang files to the service:
Keeping Translations Fresh
Nothing needs scheduling. Translations are fetched on first use and cached, and each cached bundle carries the version it was built from. That version is checked against the service's manifest on every read, so a bundle cannot go stale indefinitely.
There is a lag, though, and it is worth knowing. The manifest is itself cached
for manifest_ttl — 300 seconds by default. Until that entry expires the version
comparison is against a stale manifest, so it agrees with the cached bundle and
serves it. An edit in the service therefore appears within manifest_ttl, not on
the very next request.
Measured against a real consuming app: a value created in the service was still absent immediately afterwards, and present once the manifest cache was cleared.
Lower TRANSLATION_MANIFEST_TTL if you need edits to land faster — it costs one
small request per locale per interval — or run translations:clear-cache to force
it immediately.
Middleware for Locale Detection
Add to app/Http/Kernel.php:
This middleware detects locale from:
- Query parameter (
?locale=ar) - Header (
X-Locale: ar) - Accept-Language header
- Authenticated user preference
Using the Facade
Reading Translations
Writing Translations
Programmatic Access
How It Works
Architecture
Caching Strategy
- Memory Cache: Loaded translations stored in PHP memory
- Laravel Cache: Persistent cache with configurable TTL
- Version Checking: Manifest API checked every 5 minutes
- Automatic Invalidation: Cache refreshed when version changes
Performance
- Cached Translation: ~1-5ms (from memory)
- Laravel Cache Hit: ~5-10ms
- API Call (first time): ~50-200ms
- Manifest Check: ~10-50ms
Multi-Tenant Support
For multi-tenant applications:
Error Handling
The package handles errors gracefully:
- API Unavailable: Uses stale cache if available
- Network Timeout: Falls back to cached data
- Invalid Response: Logs error and returns empty array
- Missing Translations: Falls back to key name (Laravel default)
Enable logging for debugging:
Testing
When testing, you may want to disable API calls:
Troubleshooting
Translations not loading
- Check service URL is correct:
php artisan config:cache - Verify API is accessible:
curl https://your-service.com/translation/manifest?locale=en - Enable logging:
TRANSLATION_LOGGING=true - Check logs:
tail -f storage/logs/laravel.log
Cache not clearing
Performance issues
- Use Redis for caching instead of file cache
- Increase cache TTL if translations rarely change
License
This package is open-sourced software licensed under the MIT license.
Support
For issues and questions, please use the GitHub issue tracker.
All versions of laravel-translation-client with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/translation Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/cache Version ^10.0|^11.0|^12.0