PHP code example of darvis / laravel-google-translate
1. Go to this page and download the library: Download darvis/laravel-google-translate 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/ */
darvis / laravel-google-translate example snippets
// Get all Dutch pages without English translation
$missing = Page::getMissingTranslations('en', 'nl');
foreach ($missing as $page) {
$page->createTranslation('en');
}
// Get only source items (no pid)
$sourcePages = Page::sourceItems()->get();
// Get items in current locale
$localizedPages = Page::localized()->get();
// Get items in specific locale
$dutchPages = Page::localized('nl')->get();
// config/google-translate.php
return [
// Your Google Cloud Translation API key
'api_key' => env('GOOGLE_TRANSLATE_API_KEY'),
// Default source locale
'source_locale' => env('GOOGLE_TRANSLATE_SOURCE_LOCALE', 'nl'),
// Target locales (comma-separated in .env)
'target_locales' => explode(',', env('GOOGLE_TRANSLATE_TARGET_LOCALES', 'en')),
];