PHP code example of nabila / laravel-translation-sync
1. Go to this page and download the library: Download nabila/laravel-translation-sync 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/ */
nabila / laravel-translation-sync example snippets
// config/translation-sync.php
return [
// Translation service: 'libretranslate', 'mymemory', 'google', 'dummy'
'service' => env('TRANSLATION_SERVICE', 'libretranslate'),
// Source language (language of your translation keys)
'source_language' => env('TRANSLATION_SOURCE_LANG', 'en'),
// Target languages (defaults to Arabic - change as needed!)
'target_languages' => env('TRANSLATION_TARGET_LANGS', ['ar']),
// File format: 'php' (Laravel default) or 'json'
'file_format' => env('TRANSLATION_FILE_FORMAT', 'php'),
// Enable automatic translation
'auto_translate' => env('TRANSLATION_AUTO_TRANSLATE', false),
// Translation service configurations
'services' => [
'libretranslate' => [], // No config needed - FREE!
'mymemory' => [], // No config needed - FREE!
'google' => [
'api_key' => env('GOOGLE_TRANSLATE_API_KEY', null),
],
'freetranslateapi' => [
'url' => env('FREETRANSLATEAPI_URL', 'http://localhost:5000'),
],
// ... other services
],
];
// Original
__('Welcome :name to our site')
// After translation (Spanish)
'Welcome :name to our site' => 'Bienvenido :name a nuestro sitio'
// In your Blade template
<h1>{{ __('Welcome to our site') }}</h1>
<p>{{ __('This is a new feature') }}</p>
// In your controller
return response()->json([
'message' => __('Data saved successfully')
]);
// In tinker or a test route
use Nabila\TranslationSync\Services\Translation\TranslationServiceFactory;
$service = TranslationServiceFactory::create('google');
if ($service->isConfigured()) {
echo "✅ Google Translate is configured correctly\n";
$result = $service->translate('Hello', 'es');
echo "Test translation: {$result}\n";
} else {
echo "❌ Google Translate is not configured\n";
}
bash
# Run the test script
php test-package.php
# Or test with Laravel commands
php artisan translations:sync --stats
php artisan translations:sync --translate --dry-run
bash
# Check translation statistics
php artisan translations:sync --stats
# See what would be translated without making changes
php artisan translations:sync --dry-run
# Test with dummy service
php artisan translations:sync --service=dummy --translate
# Check service status
php artisan tinker
# Then run: app(Nabila\TranslationSync\Services\TranslationWriter::class)->isTranslationServiceAvailable()
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.