Expanding your Laravel application to support multiple languages can dramatically improve reach and SEO. By building SEO-friendly URLs, localized metadata, and hreflang tags, you help search engines index your content correctly across regions. In this guide, we’ll set up localization in Laravel, implement multi-language slugs, add localized SEO tags, update the sitemap, and build a UI language switcher.
Setting Up Laravel Localization
Laravel provides built-in localization support. Start by creating language files in resources/lang/
:
resources/lang/en/messages.php
resources/lang/tr/messages.php
Code language: Bash (bash)
// resources/lang/en/messages.php
return [
'welcome' => 'Welcome to our site!',
];
// resources/lang/tr/messages.php
return [
'welcome' => 'Sitemize hoş geldiniz!',
];
Code language: PHP (php)
You can now use {{ __('messages.welcome') }}
in Blade templates, and it will load the text based on the selected locale.
Language-Based Routes and Slugs
SEO-friendly multi-language sites should use localized URLs like /en/blog
and /tr/blog
. You can group routes by locale:
// routes/web.php
Route::group(['prefix' => '{locale}', 'middleware' => 'setlocale'], function () {
Route::get('/blog', [BlogController::class, 'index']);
Route::get('/blog/{slug}', [BlogController::class, 'show']);
});
Code language: PHP (php)
Create a setlocale
middleware to change the app locale from the route parameter:
// app/Http/Middleware/SetLocale.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\App;
class SetLocale
{
public function handle($request, Closure $next)
{
$locale = $request->route('locale', 'en');
App::setLocale($locale);
return $next($request);
}
}
Code language: PHP (php)
This ensures the correct language is applied based on the URL prefix.
Localized SEO Tags and hreflang
Each language should have its own SEO metadata. In Blade, dynamically output <title>
, meta descriptions, and hreflang tags:
<title>{{ $post->getTranslation('title', app()->getLocale()) }}</title>
<meta name="description" content="{{ $post->getTranslation('meta_description', app()->getLocale()) }}">
<!-- Hreflang for Google -->
<link rel="alternate" hreflang="en" href="{{ url('en/blog/'.$post->slug_en) }}" />
<link rel="alternate" hreflang="tr" href="{{ url('tr/blog/'.$post->slug_tr) }}" />
Code language: PHP (php)
The hreflang
attributes signal to Google which page corresponds to each language, preventing duplicate content issues.
UI Example: Language Switcher
Add a language switcher so users can easily change between languages:
<nav>
<ul>
<li><a href="/en{{ request()->getPathInfo() }}">English</a></li>
<li><a href="/tr{{ request()->getPathInfo() }}">Türkçe</a></li>
</ul>
</nav>
Code language: PHP (php)
This keeps the same path while switching the language prefix. For example, /en/blog
→ /tr/blog
.
Multi-Language Sitemaps
Update your sitemap.xml
to include entries for each language version of a page. Example for a blog post:
<url>
<loc>https://example.com/en/blog/my-post</loc>
<xhtml:link rel="alternate" hreflang="tr" href="https://example.com/tr/blog/my-post"/>
<lastmod>2025-09-01</lastmod>
</url>
Code language: HTML, XML (xml)
This helps Google index all language variations while avoiding duplicate content penalties.
Single-Language vs Multi-Language SEO
Feature | Single-Language | Multi-Language |
Reach | Only local audience | Global audience |
SEO | One set of indexed pages | Each language indexed separately |
Complexity | Simple setup | Requires localization & hreflang |
User Experience | One language for all | Visitors can read in their language |
Sitemaps | One sitemap file | Multiple language entries |
Wrapping Up
Building a multi-language SEO-friendly site in Laravel involves localized routes, translated content, SEO metadata, hreflang attributes, and updated sitemaps. By adding a language switcher UI, you improve user experience while boosting search visibility worldwide. Compared to single-language sites, multi-language setups open the door to new markets and higher organic traffic.
What’s Next
Continue enhancing your Laravel SEO stack with these guides:
0 Comments