PHP code example of casa-parks / extract-translations
1. Go to this page and download the library: Download casa-parks/extract-translations 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/ */
casa-parks / extract-translations example snippets
'providers' => [
// Other service providers...
CasaParks\ExtractTranslations\ExtractTranslationsServiceProvider::class,
],
namespace App\Composers;
use CasaParks\ExtractTranslations\Builder as TranslationsExtractorBuilder;
use Illuminate\Contracts\View\View;
class TranslationsComposer
{
/**
* The translations extractor builder.
*
* @var \CasaParks\ExtractTranslations\Builder
*/
protected $builder;
/**
* Whether the data is cached or not.
*
* @var bool
*/
protected $cached;
/**
* The view data.
*
* @var array
*/
protected $data;
/**
* Creates a new translations composer.
*
* @param \CasaParks\ExtractTranslations\Builder $builder
*/
public function __construct(TranslationsExtractorBuilder $builder)
{
$this->builder = $builder;
}
/**
* Compose the view.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
if (! $this->cached) {
$this->cache();
}
$view->with($this->data);
}
/**
* Cache the data.
*
* @return void
*/
protected function cache()
{
$this->cached = true;
$translations = $this->builder
->locales('en', 'de')
->groups('pagination', 'validation')
->service();
$this->data = compact('translations');
}
}
/**
* Register any composers for your application.
*
* @return void
*/
public function boot()
{
// ...
// assuming `layout` is your common layout template.
$this->app['view']->composer('layout', 'App\Composers\TranslationsComposer');
// ...
}
namespace App\Http\Controllers\Api;
use CasaParks\ExtractTranslations\Builder;
class TranslationController extends Controller
{
/**
* Get the available translations.
*
* @param \CasaParks\ExtractTranslations\Builder $builder
*
* @return \Illuminate\Http\JsonResponse
*/
public function list(Builder $builder)
{
return $builder->locales('en', 'de')
->groups('pagination', 'validation')
->service();
}
}