Frequently asked questions

What is darvis/livewire-inline-translation?

A Laravel package with one Livewire component, <livewire:inline-translation translation-key="website.welcome" />, that shows a translation and lets a logged in editor change it on the page itself. They click the text, a modal opens, and the new value is stored in the translations table for the current locale.

How do I let a client edit the text on a Laravel website without a full CMS?

Install darvis/livewire-inline-translation, run php artisan migrate, add <div id="inline-translation-modals"></div> to your layout and render <livewire:inline-translation translation-key="website.welcome" /> where the text belongs. Someone logged in on the configured guard sees a dashed underline, clicks it, edits the text in a modal and saves. Everyone else gets the text without the underline.

Which PHP, Laravel and Livewire versions does it support, and what does it cost?

PHP 8.2 or higher, Laravel 11, 12 or 13, and Livewire 3 or 4. It is free and open source under the MIT license, needs a database for the edited texts, and uses no external service.

Where does the edited translation end up, in my language files or in the database?

In the database, in the translations table, one row per locale, group and key. Your language files are never written to. The component reads the database first and falls back to __($key), so a text nobody has edited still comes from your language file.

Who is allowed to edit a translation?

Whoever is logged in on the guard from the inline-translation.guard setting (env INLINE_TRANSLATION_GUARD). The default is web, so out of the box every logged in user may edit every translation. Point it at a guard for editors, or extend the component and override the protected isAuthorized() method to require a permission.

Is it safe to let someone edit text on a live page?

Since version 1.3.1 the guard is checked when the component is drawn, in openModal() and in save(); the last two answer 403 for a visitor who may not edit, and the translation key is locked so the browser cannot change it. The stored value is rendered as HTML without sanitising, so everyone who may edit can put any markup on the page, including script. Give the guard only to people you trust with that, or strip tags in your own save().

Can an editor use bold text, lists or line breaks in a translation?

Yes. With :html="true" on the tag the modal shows a small editor with bold, italic and a bullet list instead of a text field. The value is rendered as HTML in both modes.

The edit modal does not appear or is cut off. What is wrong?

The modal is teleported by Alpine into the element named by modal_container_id, inline-translation-modals by default. That element has to exist in your layout and sit outside anything with overflow: hidden, a transform or its own z-index. Put an empty div with that id at the end of the body.

Why does __() still return the old text after someone edited a translation?

Only the component reads the database; __(), @lang and trans() keep reading your language files. Outside the component, use Translation::getTranslation($locale, 'website', 'welcome') ?? __('website.welcome'). The other way round, a plain __('website.welcome') is how you show a text that nobody may edit.

Do I have to publish a migration?

No. The translations table comes along with php artisan migrate. Only the config (inline-translation-config) and the view (inline-translation-views) are publishable.