Localization (i18n)
Brok components are translation-ready the moment you copy them in. User-facing
labels are already wrapped in Laravel's __()
helper, and every primitive is authored with CSS logical properties — so the same
copied markup serves any language, and flips for right-to-left scripts with a single
dir attribute. There is no extra package, no
build step, and nothing to re-generate: you add translation lines and, optionally,
set the document direction.
What you get for free
-
Strings call
__(). Visible labels in the components ship wrapped in the translation helper, so a matching lang line is all it takes to swap the copy per locale. -
Logical properties mirror under RTL.
Spacing, alignment and position use
ms/me,ps/pe,start/endandtext-start/text-end— setdir="rtl"and the layout flips automatically. See the RTL guide for the full mechanics. - No runtime dependency. The copied code is plain Blade — it uses your app's existing locale, lang files and any locale-switching package you already run.
Localize a copied component
Because the labels already call __(), localizing
is just standard Laravel translation work.
Set the application locale
config/app.php
(the APP_LOCALE env var), or switch it per
request with App::setLocale($locale) in
middleware.
Add a translation line
lang/<locale>/*.php file. A
component that renders {{ __('Save changes') }}
just needs that string keyed in each locale.
// lang/es/messages.php
return [
'Save changes' => 'Guardar cambios',
'Search…' => 'Buscar…',
];
Pass dynamic copy through the translator
{{-- In a copied component --}}
<h2>{{ __('Welcome back') }}</h2>
<p>{{ __(':count items in your cart', ['count' => $count]) }}</p>
Flip direction for RTL languages
Arabic, Hebrew, Persian and Urdu read right-to-left. Set the document
dir alongside
lang and every component mirrors — no per-component
work, because they are built on logical properties.
{{-- Drive lang + dir from the active locale --}}
@php($rtl = in_array(app()->getLocale(), ['ar', 'he', 'fa', 'ur'], true))
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" dir="{{ $rtl ? 'rtl' : 'ltr' }}">
This is exactly how the Brok docs site itself wires its
<html> tag — the layout reads
app()->getLocale() and resolves
dir from it. You can also scope direction to a
subtree (a single RTL widget on an otherwise LTR page) by setting
dir="rtl" on a wrapping element.
Gotchas
Note
php artisan lang:publish if you want Laravel's
stock validation/auth lang files as a starting point.Note
rtl:-scale-x-100 so they point the right way.
The RTL guide
covers this and the numbers/code-stay-LTR rule in depth.Warning
__() so a future locale doesn't require a second
edit pass.