Setting up website localization for English language
Adding English locale to your website is a standard task when reaching international audience. English is the fallback language for most i18n systems: if translation for another language is missing, the English version is shown.
Translation structure
resources/
lang/
en/
messages.php
validation.php
auth.php
pagination.php
ru/
messages.php
...
// resources/lang/en/messages.php
return [
'welcome' => 'Welcome to our website',
'catalog' => 'Catalog',
'cart' => 'Shopping Cart',
'checkout' => 'Checkout',
'search' => 'Search',
'add_to_cart' => 'Add to Cart',
'price' => 'Price',
'in_stock' => 'In Stock',
'out_of_stock' => 'Out of Stock',
'items_count' => ':count item|:count items',
];
Laravel supports pluralization via |:
trans_choice('messages.items_count', 1) // "1 item"
trans_choice('messages.items_count', 5) // "5 items"
Formatting in American and British English
// en-US vs en-GB — different date and number formats
const date = new Date('2026-03-28')
new Intl.DateTimeFormat('en-US').format(date) // "3/28/2026"
new Intl.DateTimeFormat('en-GB').format(date) // "28/03/2026"
new Intl.DateTimeFormat('en-US', { dateStyle: 'long' }).format(date)
// "March 28, 2026"
new Intl.DateTimeFormat('en-GB', { dateStyle: 'long' }).format(date)
// "28 March 2026"
// Numbers
new Intl.NumberFormat('en-US').format(1234567.89) // "1,234,567.89"
new Intl.NumberFormat('en-GB').format(1234567.89) // "1,234,567.89"
// Currency
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(99.99)
// "$99.99"
new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' }).format(99.99)
// "£99.99"
Detecting browser's preferred language
function detectLanguage(available: string[]): string {
const preferred = navigator.languages ?? [navigator.language]
for (const lang of preferred) {
// Exact match: 'en-US'
if (available.includes(lang)) return lang
// Partial: 'en-US' → 'en'
const base = lang.split('-')[0]
if (available.includes(base)) return base
}
return 'en' // fallback
}
const userLang = detectLanguage(['ru', 'en', 'de'])
On the server: detection via Accept-Language header
// Laravel Middleware
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
class SetLocale
{
private array $available = ['ru', 'en', 'de', 'fr'];
public function handle(Request $request, Closure $next): mixed
{
// Priority: explicit parameter > session > browser header
$locale = $request->get('lang')
?? $request->session()->get('locale')
?? $this->parseAcceptLanguage($request->header('Accept-Language'));
$locale = in_array($locale, $this->available) ? $locale : 'ru';
App::setLocale($locale);
return $next($request);
}
private function parseAcceptLanguage(?string $header): string
{
if (!$header) return 'ru';
preg_match_all('/([a-z]{2})(?:-[A-Z]{2})?(?:;q=([0-9.]+))?/', $header, $m);
$langs = array_combine($m[1], array_map(
fn($q) => $q === '' ? 1.0 : (float) $q,
$m[2]
));
arsort($langs);
foreach (array_keys($langs) as $lang) {
if (in_array($lang, $this->available)) return $lang;
}
return 'ru';
}
}
English as default language for API
Many projects use English as API response language regardless of user locale:
// Error messages — always in English in API
return response()->json([
'error' => 'Resource not found',
'code' => 'NOT_FOUND',
], 404);
// User-facing text — localized
return response()->json([
'message' => __('messages.order_placed'), // per user locale
'data' => $order,
]);
SEO: hreflang
<link rel="alternate" hreflang="en" href="https://example.com/en/" />
<link rel="alternate" hreflang="en-US" href="https://example.com/en-us/" />
<link rel="alternate" hreflang="ru" href="https://example.com/" />
<link rel="alternate" hreflang="x-default" href="https://example.com/" />
x-default indicates the page for users whose language doesn't match any available option.
Timeframe
Connecting English translations, configuring middleware and hreflang — 1 working day.







