GithubHelp home page GithubHelp logo

site-language-redirection's Introduction

TYPO3 Site Language Redirection

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

  1. 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
      Settings of new scheduler task
      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.

  2. Update the preferred method in your site configuration in the tab Site Language Redirection. Defaults to HTTP headers.
    Screenshot of Site Language Redirection tab in site configuration
    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'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.