Translating

The words a component says on its own (a field's "Clear", a date picker's "Previous month", a tag field's "Removed [email protected].", an audio player's "Pause") come from the package's language files, through Laravel's translator, under the ds namespace:

__('ds::forms.clear')          // "Clear"
__('ds::script.audio.pause')   // "Pause"

So they follow app()->getLocale() like the rest of your app, and the English is exactly what 2.0 printed before it had a language file: the render tests hold the English output byte for byte.

Changing a word, or adding a language

Publish the files:

php artisan vendor:publish --tag=blade-ui-lang

They land in lang/vendor/ds/en/. Edit a line there to change the English, or copy the folder to lang/vendor/ds/fr/ (any locale) and translate it. Laravel reads lang/vendor/ds/{locale}/{file}.php before the package's own, key by key, so a file that holds only the lines you changed is enough: the rest fall back to the package's English.

A worked second locale lives in the package's tests (tests/Fixtures/lang/vendor/ds/fr/, laid out as an app's published files), with a test that renders the form controls in French. It is an example of the mechanism, not a shipped translation.

A prop still wins

Every component that has a prop for one of its words keeps it, and a value you pass beats the language file:

<x-ds::copy-button :value="$key" />                   {{-- __('ds::forms.copy-button.label'): "Copy" --}}
<x-ds::copy-button :value="$key" label="Dupliquer" />  {{-- "Dupliquer", whatever the locale --}}

Words the script speaks

The script has no sentences of its own. Every word it writes into the page (a button that turns from "Play" to "Pause", "Updated" after a pull to refresh, "Edit Title: Q3 roadmap") is handed to it by the component's view, from the language file, in the server's locale. So a page rendered in French is French in the browser too, with nothing to configure on the client.

The one exception is the keys' own names in a shortcut ("Ctrl", "Esc", and "Command", "Option" as a screen reader hears them on a Mac), which stay as printed on the key caps in 2.0.

Numbers, dates and money

Those are not in the language files. The components that format them take a locale (or read app()->getLocale()) and format with PHP's Intl on the server and the browser's Intl in the script: month names, decimal marks and currency symbols come from the locale, not from a translation.

What is translated in 2.0

Through the language filesFiles
Every word the script speaks, and the media components' controls (audio player, lightbox, dictation, code block, expandable text, pull to refresh)script.php
The form controls: input, select, combobox, number, tag, phone, money, mention, shortcut and OTP fields, slider, colour, date and time pickers, calendar, file and avatar upload, rating, copy, confirm and hold buttons, filter bar and chip, theme switcher, save bar, inline edit, password strengthforms.php

The other components' fixed words (an agent status's "Thinking", a notification's "Mark as read", an empty state's defaults and the like) are still English literals in their views in 2.0, each with a prop to override it where it has one. They move to the language files after 2.0; the package's StrayLiteralsTest lists them.


From the package repo: edit this page on GitHub.

Was this page helpful?