Download the PHP package ofat/laravel-translatable-routes without Composer
On this page you can find all versions of the php package ofat/laravel-translatable-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ofat/laravel-translatable-routes
More information about ofat/laravel-translatable-routes
Files in ofat/laravel-translatable-routes
Package laravel-translatable-routes
Short Description Laravel package for translatable routes
License MIT
Informations about the package laravel-translatable-routes
Package to make Laravel routes translatable
This package provides you possibility to translate your urls. For example:
It is very useful for good search engine optimization (seo).
Installation
-
Install package via composer:
- Add your translations to resource/lang like usual Laravel translations.
resources/lang/en.json:
resources/lang/de.json:
- Define your supported locales in config file:
config/translatable-routes.php:
Routing
Once the package is installed you can use your translation strings in route defining with square brackets.
To define group with added language prefix you can use localeGroup
method
and write all routes inside it.
Named Routes
You can also use names for your routes inside localeGroup. It will create separate route name for each locale:
URL Generating
Generate URL by route
You can use normal route
function to generate url in current locale:
Depends on current locale it will create /en/country/...
or /de/land/...
You can use routeInLocale
method if you need to generate URL in concrete locale
or just add locale in your route name:
Generate URL by path
You can also use translation keys in square brackets in url
function.
But it doesn't add locale prefix to your URL
To add locale prefix to your url:
Locale switch
To generate url for language switching you can use named route switch-locale
All static routes will be switching by default. But for routes with parameters you can add strategies and define logic for translation:
In this case if you try to switch language on page /en/country/france
it will redirect to
/fr/les-pays/la-france
In isApplicable
method you should write your logic for checking if
route is determined to your group needs.
In getTranslatedUrl
method you should write your logic to generate url for
your route on new locale