Download the PHP package reachweb/locale-lander without Composer
On this page you can find all versions of the php package reachweb/locale-lander. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download reachweb/locale-lander
More information about reachweb/locale-lander
Files in reachweb/locale-lander
Package locale-lander
Short Description Locale Lander for Statamic
License mit
Homepage https://www.reach.gr
Informations about the package locale-lander
Locale Lander
Locale Lander is a simple addon for Statamic, particularly useful for multi-site setups involving multiple languages. It redirects users to the default language of their browser during their first visit or displays a banner informing the user that the content is available in their native language.
How to Install
Install using composer:
How to Use (Redirection)
To use the redirection feature, no additional configuration is needed after installation. The addon should function right out of the box.
How to Use (Banner)
To use the banner feature, Locale Lander provides a tag called, you guessed it, locale-lander
.
First, you must disable automatic redirection. Publish the config file:
and in config/locale-lander.php
disable redirection:
Then, you can use the tag by adding the necessary code to a file that loads on all pages of your website, usually layout.antlers.html
.
The tag will return an array
that always contains an 'entry' key. If the Entry is unavailable in this locale, entry
will be false. Otherwise, it will contain the title
and the url
of the entry. A site
key is also provided with information about the user's locale site.
As you might have guessed, the addon contains an example banner template, styled with Tailwind CSS, that works out of the box.
Publish the template:
and you should be good to go. If you are not using Tailwind CSS, you will need to style it yourself.
In case you want to implement your own version, note that you should set a cookie named locale_banner_closed
to prevent showing the banner to users who have closed it.
How it Works
This addon automatically applies a middleware in the statamic.web
middleware group. Here's the process:
- It checks the user's browser language and the sites defined in
statamic/sites.php
. - If the current site's locale differs from the user's browser, it verifies if a site for that locale exists.
- If such a site exists and the current entry is available in that locale, it redirects the user there.
- A session variable is set to avoid repetitive redirection. This prevents redirect loops and accommodates users who prefer a different locale than their browser’s default.
Common Issues
- The addon functions with URLs resolving to an
Entry
. It won't work if the first page a user visits isn't an Entry. (Future improvements are planned for this issue.) - If the site's default locale matches the user's, or if the user initially visits the site in their locale but chooses to visit a different one, they will be redirected back to their original locale once. I am currently working to resolve this issue, but it may require modifications to the language switcher.
All versions of locale-lander with dependencies
statamic/cms Version 4.51.0|^5.0.0
symfony/intl Version ^6.4 || ^7.0