mohsinqk / site-language-redirection
Installs: 138
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 15
Type:typo3-cms-extension
Requires
- geoip2/geoip2: ^2.9.0
- typo3/cms-core: ^9.5.0||^10.4||^11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
Suggests
Replaces
- typo3-ter/site-language-redirection: v2.4.0
This package is auto-updated.
Last update: 2024-10-27 12:13:38 UTC
README
This extension is a copy of the TYPO3 Site Language Redirection extension. As I have added a new feature to disable language redirect for multisite enviroments of TYPO3. So this repo is usefull untill author of the base extension merge my change request for my feature.
PSR-15 middleware to redirect user to correct site language.
- Language detection is based on HTTP headers (browser language) or IP address.
- When the user switches the language, a cookie gets set to save the new language as preferred language.
How it works
Example of how the extensions determines the site to redirect to via HTTP headers:
If Accept-Language is en-US,de-AT
it looks for sites with an hreflang of en-US
. If there is no match it then looks for en
. If there is still no match it repeats the same logic with de-AT
and so on.
Installation
Install via Extension Manager or composer.
composer require urbantrout/site-language-redirection
Enable IP address based redirects
-
Update the GeoIP2 database file for IP address based redirects via CLI or Scheduler.
- CLI
./vendor/bin/typo3 sitelanguageredirection:updatedb
- Scheduler Create new task of class Excute console commands and set Schedulable Command to sitelanguageredirection:updatedb Use this option to periodically update your database file.
This step creates a file under
\TYPO3\CMS\Core\Core\Environment::getVarPath() . '/sitelanguageredirection/'
with all the geolocation information. Note: This does not alter your SQL database. - CLI
-
Update the preferred method in your site configuration in the tab Site Language Redirection. Defaults to HTTP headers. Changing this value to IP address updates
config/sites/<sitename>/config.yaml
and adds the following line of code:
SiteLanguageRedirectionMethod: 2
Configure Language Fallbacks
This feature adds the possibility to define fallback languages. So for instance, if there's no italian version of the website, redirect to english version, and so on.
Site configuration would look like this with optional SiteLanguageRedirectionFallbacks
:
SiteLanguageRedirectionMethod: 1 SiteLanguageRedirectionFallbacks: fr: 'en' it: 'en'