DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

EXT: cs_IP2Language

Author:Kasper Skårhøj
Created:2002-11-01T00:32:00
Changed by:Pascal Rossa
Changed:2010-07-29T18:33:23
Author:Pascal Rossa
Email:rossa@creatissimo.net
Info 3:
Info 4:

EXT: cs_IP2Language

Extension Key: cs_IP2Language

Copyright 2010, Pascal Rossa, <rossa@creatissimo.net>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

- a GNU/GPL CMS/Framework available from www.typo3.com

Table of Contents

EXT: cs_IP2Language 1

Introduction 1

What does it do? 1

Users manual 1

Adminstration 1

Detailed workflow 1

Configuration 2

Configuring country languages 2

Disable IP2Language language detection 3

Disable IP2Language language detection for robots 3

Detect language only on first hit 4

Detect language only on specified pages 4

Reference 4

The MaxMind geoIP country database 4

Known problems 5

To-Do list 5

Changelog 5

Introduction

What does it do?

The cs_IP2Language extension uses the free database by MaxMind to determine the country of residence for visitors based on their IP address.

The extension will make sure every visitor browses the correct language for his country of residence. So for example certain languages can be denied to users from specified countries.

Intended uses

This extension is useful for sites that provide localized content and want to preselect the probably correct language.

Users manual

The cs_IP2Language extension is an include only extension and provides no GUI whatsoever.

Adminstration

Typo3 administrators can edit TypoScript constants and TypoScript setup parameters to configure the extension.

If the country of residence for a visitor could be found, the corresponding country ISOCode and language UID will be written in TypoScript setup:

plugin.tx_csip2language_pi1.detected.country
     plugin.tx_csip2language_pi1.detected.language

Detailed workflow

The cs_IP2Langauge extension is included as library upon every pagerequest.

On every page request the extension checks if a languagedetection should be done. This depends on the setup. It is possible to deactivate the languagedetection via TypoScript or specify that the detection should only be done on the first hit of the homepage or even only on specified pages.

If a languagedetection should be done the extension tries to find the country of residence for the requesting IP.

If the country can be determined – the IP is found in the MaxMind geoIP database – the extension reads its TypoScript configuration and looks for a LanguageID configured for the country determined in step 2. If there is no LanguageID configured for the detected country the defined default language will be used.

The extension checks whether the currently requested language is equal to the LanguageID found in step 3. If that is the case no action is performed.

Otherwise a link to the current page with the detected languageparameter is build and a Location Redirect header is sent to the browser.

Configuration

Configuring country languages

Currently the most important option to configure the extension is to embed the static template in the Template at “Include Static (from Extension)” and provide languageUIDs for certain country ISOCodes.

img-1

The ISOCodes ↔ Language mapping is done via TypoScript setup.The cs_IP2Language uses the two-letter ISO 3166 standard to identify countries by default.

((generated))
Example
plugin.tx_csip2language_pi1 {
             defaultLanguage = 0
             country.languages {
                     EN = 0
                     DE = 1
             }
     }

The configuration above tells the extension that every visitor with an IP residing in Germany will visit the page localized with the language with UID 1. Visitors with an IP residing in unspecified country (e.g. Spain) or unknown country will visit the page localized with the default language with UID 0.Additional countries can be configured likewise.

All other configuration parameters can be set with the Constant Editor:

img-2

Disable IP2Language language detection

It might be useful to have the extension disabled on some pages or even pagetrees.If thats the case the “disable” constant within the constant editor has to be enabled or the following line has to be added to the TS Setup:

((generated))
Example
plugin.tx_csip2language_pi1.disable = 1

Disable IP2Language language detection for robots

It might be useful to have the extension disabled for robots (default).If this option is enabled the HTTP_USER_AGENT is checked agains a database with some names of robots. These database entries could be edit or supplemented within the list-view. The database is based on ”The Robots Database” http://www.robotstxt.org/db.html .To enable the language detection even for robots the “disableforbots” constant within the constant editor has to be disabled or the following line has to be added to the TS Setup:

((generated))
Example
plugin.tx_csip2language_pi1.disableforbots = 0

Detect language only on first hit

It might be useful to preselect the language only on the first hit of the homepage. Otherwise the visitor won't be able to change the language, because the detection would redirect the user to the autodetected language on every page load.If set a session variable is written at the first language detection. If this session variable is set, no further detections and redirects are made.If the language should be detected on every page load, the “detectonfirsthitonly” constant within the constant editor has to be disabled or the following line has to be added to the TS Setup:

((generated))
Example
plugin.tx_csip2language_pi1.detectonfirsthitonly = 0

Detect language only on specified pages

It might be useful to detected the language only on specified pages, e.g. homepage.If this is the case a comma separated list of the page UIDs, where the detection should be done, has to be set to the “detectonpages” constant within the constant editor.If a detection should be done on every page detectonpages has to be 0 (default).

((generated))
Example
If the language detection should only work on the pages with the UIDs 5, 12 and 89:
     plugin.tx_csip2language_pi1.detectonpages = 5,12,89

Reference

country.languages

Property

country.languages

Data type

Array

Description

Configures LanguageUIDs for country ISOCodes

Default

country.languages {

EN = 0

DE = 1

}

defaultLanguage

Property

defaultLanguage

Data type

Integer

Description

UID of the default language.This language will be used if the country couldn't be detected or no language is defined for the detected country in country.languages

Default

0

disable

Property

disable

Data type

Boolean

Description

Disables the language detection

Default

0

disableforbots

Property

disableforbots

Data type

Boolean

Description

Disables the language detection for robots

Default

1

detectonfirsthitonly

Property

detectonfirsthitonly

Data type

Boolean

Description

If set the language is only detected on the fist hit of the homepage.A session variable is written on the first detection. If this session variable is set, no further detections and redirects are made.

Default

1

detectonpages

Property

detectonpages

Data type

String

Description

If set to 0 the detection is made on every page.

If detectonpages > 0 or contains a comma separated list of page UIDs the detection is only made if the UID of the current page is specified in this list.

Default

0

detected.country

Property

detected.country

Data type

String

Description

The country ISOCode is written to this variable, if a country was detected.

Default

detected.language

Property

detected.language

Data type

Integer

Description

The UID of the detected Language is written to this variable.

Default

The MaxMind geoIP country database

The extension relies on the geoIP country database from MaxMind, available freely on http://www.maxmind.com

The database is licensed under the open data license.

The database is updated on a regular basis, so a cronjob should be configured to download the current database once in a while. This is the only way to make sure the IP to country mapping of the extension is always up to date and generates as much correct results as possible.

As of now the most recent geoIP database can be obtained here:

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/Geo IP.dat.gz

It has to be downloaded and gunziped to the 'geodata' subdirectory of the extension directory.

A shellscript (updategeodata.sh) to do this is stored in the 'geodata' subdirectory of the extension directory.This script requires wget and gunzip. Make sure that this script is executable (chmod 755)!To regulary update the GeoIP.dat a cronjob should be set up:

((generated))
Example
Update GeoIP.dat at 3 a every night.

 3 * * * * sudo -u WEBUSER /PATH/TO/WEBDIR/typo3conf/ext/cs_ip2language/geodata/updategeodata.sh

MaxMind also provides a free PHP library licensed under LGPL that accesses that database. The extension already comes with that PHP library (stored in 'lib' subdirectory of the extension directory). It is the original code as provided by MaxMind.

Known problems

None. If you find a bug please contact me.

To-Do list

?

Changelog

((generated))

0.9.0

first public release

img-3 EXT: cs_IP2Language - 5