PHP code example of our-edu / laravel-translation-client
1. Go to this page and download the library: Download our-edu/laravel-translation-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
our-edu / laravel-translation-client example snippets
'available_locales' => ['en', 'ar', 'fr'],
return [
// Enable API translation integration and import commands (disabled by default)
'enabled' => env('TRANSLATION_CLIENT_ENABLED', false),
// Translation service base URL
'service_url' => env('TRANSLATION_SERVICE_URL', 'http://localhost'),
// Cache TTL in seconds
'manifest_ttl' => env('TRANSLATION_MANIFEST_TTL', 300), // 5 minutes
'bundle_ttl' => env('TRANSLATION_BUNDLE_TTL', 3600), // 1 hour
// Client type: backend, frontend, mobile
'client' => env('TRANSLATION_CLIENT', 'backend'),
// HTTP timeout in seconds
'http_timeout' => env('TRANSLATION_HTTP_TIMEOUT', 10),
// Use stale cache on API failure
'fallback_on_error' => env('TRANSLATION_FALLBACK_ON_ERROR', true),
// Cache store (null = default)
'cache_store' => env('TRANSLATION_CACHE_STORE'),
// Add
// In controllers
__('messages.welcome')
trans('validation.Ahmed'])
use OurEdu\TranslationClient\Services\TranslationClient;
class MyService
{
public function __construct(
private TranslationClient $translationClient
) {}
public function getTranslations()
{
return $this->translationClient->fetchBundle('ar', ['messages']);
}
}
// Set tenant dynamically based on request
config(['translation-client.tenant_id' => $currentTenant->id]);
// Or extend the TranslationClient
class MultiTenantTranslationClient extends TranslationClient
{
public function __construct()
{
parent::__construct();
$this->tenantUuid = auth()->user()?->tenant_uuid;
}
}
// In tests/TestCase.php
protected function setUp(): void
{
parent::setUp();
// Mock the translation client
$this->mock(TranslationClient::class, function ($mock) {
$mock->shouldReceive('loadTranslations')
->andReturn(['messages.welcome' => 'Welcome']);
});
}