PHP code example of aw-studio / localize

1. Go to this page and download the library: Download aw-studio/localize 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/ */

    

aw-studio / localize example snippets


// lang/de/routes.php

return [
    'home' => 'startseite'
];

Route::trans('/__(routes.home)', HomeController::class)->name('home');

<a href="{{ __route('home') }}">
    ...
</a>

@foreach (__routes($routeParameters ?? null) as $route)
    <a href="{{ $route->link }}">
        {{ $route->locale }}
    </a>
@endforeach

Route::trans('/__(routes.posts)/{slug}', PostController::class)->name('posts.show');

$post = Post::whereHas('translations', function($query) use($slug) {
        $query->where('slug', $slug)->where('locale', app()->getLocale());
    })
    ->with('translations')
    ->first();

$slugs = $post->translations->mapWithKeys(function($item) {
    return [$item->locale => $item->slug];
})->toArray();


return view('posts.show')->with([
    'post' => $post,
    'routeParameters' => ['slug' => $slugs]
]);

@foreach (__routes($routeParameters ?? null) as $route)
    {{ $route->link }}
@endforeach