Docs Translations
Laratic makes it simple to localize your docs. The documentation controller automatically looks for a translation in the active language and falls back to English if one isn’t available.
How Locale Fallback Works
All docs pages are handled by App\Http\Controllers\DocumentationController.
When someone visits /docs/{topic}, the controller:
- Gets the current locale using
app()->getLocale(). - Turns the topic (e.g.
blog/translations) into a dot-path. - Tries to load
resources/views/pages/docs/<locale>/<topic>.blade.php. - If it doesn’t exist and the locale isn’t
en, it falls back to the English version underresources/views/pages/docs/en.
For the changelog topic, the lookup order is:
resources/views/pages/docs/<locale>/changelog.blade.phpresources/views/pages/docs/en/changelog.blade.phpresources/views/pages/docs/changelog.blade.php(supported, but not used by default)
Adding a Translation
To add a translated docs page (for example, Spanish es):
- Create the locale folder if it doesn't exist:
resources/views/pages/docs/es. - Copy the English page into that folder. For example:
resources/views/pages/docs/en/changelog.blade.php→resources/views/pages/docs/es/changelog.blade.php - Translate the text in the new file while keeping the same layout and Blade components.
- Switch the app locale to
es, then visit/docs/changelogto see the result.
The translated file name and path structure must exactly match the English version. Only the locale folder changes (e.g., from 'en' to 'es'). The file name and any subdirectories must remain identical for the locale fallback to work correctly.
For example, if you have an English file at:
resources/views/pages/docs/en/documentation/translations.blade.php
The Spanish translation must be at:
resources/views/pages/docs/es/documentation/translations.blade.php
Notice that only en changes to es—the documentation/translations.blade.php part stays exactly the same.