Documentation

LanguageAcceptParser
in package

This parser allows an application to determine what language it should use to answer a request. To do so, it reads the Accept-Language header from a browser's request.

Please note, that a browser may not be sending any accept-language header, or requesting a language your application may not support.

Tags
author

César de la Cal Bretschneider cesar@magic3w.com

Table of Contents

$default  : string
Contains the default locale to be included in the list of locales in the event that the user did not specify any locale in the header.
$header  : string
Contains the header string with a valid "Accept-Language" header format that should be scanned for locales.
__construct()  : mixed
Creates a new Parser, which retrieves the language from either a string you provided or the system header.
parse()  : array<string|int, LanguageAccept>
Parses the Accept Language header and returns a list of locales that it extracted.

Properties

$default

Contains the default locale to be included in the list of locales in the event that the user did not specify any locale in the header.

private string $default

Methods

__construct()

Creates a new Parser, which retrieves the language from either a string you provided or the system header.

public __construct(string $default[, string $header = null ]) : mixed

The default locale will ensure that this function always returns data and provide you with the option to always use fallbacks. Please note that, your application should provide those fallbacks.

Parameters
$default : string

Provides a default language in case there was none.

$header : string = null
Tags
see
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
Return values
mixed

parse()

Parses the Accept Language header and returns a list of locales that it extracted.

public parse() : array<string|int, LanguageAccept>

Your application can then check if, and how, it wishes to localize itself to provide a proper experience for the user.

Return values
array<string|int, LanguageAccept>

Search results