- LaralCN-UI: shadcn-style Blade components and blocks you own · part 12 of 26
- Laravel
- Blade
- Javascript
- LaralCN-UI
- RTL
LaralCN-UI docs in Arabic, and code colours that only worked on my machine
After part 9, the /ar docs pages were right to left but every word on them was still English, and the code blocks on production had no colours at all. This post covers both fixes: 191 translated strings plus an Arabic demo for every component, and a browser fallback for Shiki on a server whose PHP-FPM has no Node.
5 min read
After part 9, the /ar docs pages were right to left but every word on them was still English, and the code blocks on production had no colours at all. This post covers both fixes: 191 translated strings plus an Arabic demo for every component, and a browser fallback for Shiki on a server whose PHP-FPM has no Node. Both shipped in PR #6, as a website-only change.
Right to left with English text reads backwards
Part 9 made the components and the docs layout direction-aware, and a global middleware gave every page an /ar twin. But the twin still said "Installation" and "Usage" and rendered the English demos. In a right-to-left layout that is worse than plain English, because punctuation follows the direction. The accordion demo asks "Is it accessible?", and inside an RTL container the question mark lands on the wrong end, so the page showed "?Is it accessible".
That made the case for real Arabic content: the /ar pages were only useful for checking the layout, and they made the components look broken.
Every string goes through __()
Every string on the docs site now goes through Laravel's __() helper, with the Arabic in website/lang/ar.json. That file has 191 strings. It covers the sidebar, page headings, the guides, the landing page and the footer, plus every component and block description, the category names and the component notes from each component.json.
Using the English text as the key kept the change small. The English pages render exactly what they did before, and a missing translation falls back to English instead of showing a key like docs.sidebar.forms.
The notes needed one more step. They mix prose with code: "Pass name, :options as ..." and so on. Inside an Arabic sentence, a span like ['value' => 'Label'] gets its brackets and arrows reordered by the bidi algorithm. So backtick spans in notes become code elements with their own direction:
{!! preg_replace('/`([^`]+)`/', '<code dir="ltr" class="text-foreground">$1</code>', e(__($entry['tailwind']['notes']))) !!}
The e() runs first, so the notes are escaped before the replacement adds the only markup they can contain.
Arabic demos with an English fallback
The preview on each component page renders a demo view. Arabic demos now live next to the English ones, under resources/views/examples/ar/<name>.blade.php, and the controller picks one by the current locale:
private function demoView(string $name): string
{
$localized = "examples." . app()->getLocale() . ".{$name}";
return view()->exists($localized) ? $localized : "examples.{$name}";
}
All 35 components had an Arabic demo when this shipped, so the fallback is there for new components that land before their translation does. The Code tab shows whichever file was rendered, so the Arabic page shows the Arabic demo's source. Pagination's Arabic demo passes label="السابق" and label="التالي", because those labels come from the component's props and are a good example of why every visible string should be a prop.
Some things stay English on purpose. The Usage and Props blocks are code. The Markdown channel (each page's .md version and llms.txt) is for tools and language models, and block prop docs are read straight from the block source.
Production had no syntax colours
The second problem was on production only: every code block was flat grey.
The site highlights code with Shiki through spatie/shiki-php, which shells out to Node. Locally that works. On the VPS, PHP-FPM has no Node, so every call threw. The code-block component already caught that, because a missing binary should never turn a docs page into a 500, and fell back to plain text. It failed quietly, which is what I asked it to do, and quiet failures are easy to miss.
Rather than chase Node onto the server, I let the browser finish the job when the server cannot. The fallback block now carries the language:
<pre class="shiki" data-highlight="{{ $language }}"
style="background-color:#24292e;color:#e1e4e8"><code>{{ $code }}</code></pre>
And app.js picks those up, loading Shiki only when at least one exists:
const plainBlocks = document.querySelectorAll('pre[data-highlight]');
if (plainBlocks.length) {
Promise.all([
import('shiki/core'),
import('shiki/engine/javascript'),
]).then(async ([{ createHighlighterCore }, { createJavaScriptRegexEngine }]) => {
const highlighter = await createHighlighterCore({
themes: [import('shiki/themes/github-dark.mjs')],
// blade, shellscript, css, javascript
engine: createJavaScriptRegexEngine({ forgiving: true }),
});
// ...replace each <pre> with highlighter.codeToHtml(...)
});
}
Two choices keep that cheap. It uses shiki/core with the JavaScript regex engine, so there is no WASM file to download. And it loads only four grammars (blade, shellscript, css and javascript) instead of Shiki's full bundle. On a machine where the server highlighter works, no block carries data-highlight and none of this loads.
I checked it in Chrome by forcing the server highlighter off: blocks got coloured on both / and /ar, with the same github-dark theme the server uses.
Tests and deploy
The package suite passed at 130 tests and the website suite at 15. Every /ar/components/<name> page returned 200, as did the /ar guides and three /ar/blocks pages. This was a website-only change, so there was no release: pull and run deploy.sh, and the committed build assets carry the new app.js.
Where it is
composer require --dev safi/laralcn-ui
php artisan ui:init
php artisan ui:add accordion
Docs: https://laralcn-ui.abdulkadersafi.com, and in Arabic at https://laralcn-ui.abdulkadersafi.com/ar. GitHub: https://github.com/Abdulkader-Safi/LaralCN-UI. MIT licensed.
Next: the first of the seven new components, a combobox that works with a plain form, wire:model and x-model.
Last updated 1 Dec 2026 · filed under Laravel, blade, javascript, laralcn-ui, rtl