xref: /web-php/include/langchooser.inc (revision 38ef33f9)
1<?php
2
3/*
4
5 This script tries to guess what language to use for
6 language dependent operations (lookup, search, books
7 page display, etc.), considering all possible factors
8 affecting language selection.
9
10 After this script run, $LANG is set to the preferred
11 language, or is the empty string, if no manual is
12 available on the current mirror site.
13
14 $EXPL_LANG will also be set to the explicitly provided
15 language, or will not exist if there are only implications
16 on the preferred language.
17
18 $UA_LANGS will contain the user agent language settings
19 parsed as an array. The language names are corrected for
20 php.net usage in this array. This is just to present to
21 the user in case he would like to get information on the
22 parsed language information (see /my.php).
23
24 The $_SERVER['STRIPPED_URI'] var is also set to the
25 stripped request URI (in case of a shortcut, the
26 language is stipped, so the shortcut handling code
27 is not bothered with it).
28
29*/
30
31use phpweb\LangChooser;
32
33require_once __DIR__ . '/../src/autoload.php';
34
35// Default STRIPPED_URI
36$_SERVER['STRIPPED_URI'] = htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8');
37
38// The code is encapsulated in a function,
39// so the variable namespace is not polluted
40list($LANG, $EXPL_LANG) = (new LangChooser($LANGUAGES, $INACTIVE_ONLINE_LANGUAGES, myphpnet_language(), default_language() ?: ''))->chooseCode(
41    $_REQUEST['lang'] ?? null,
42    $_SERVER['REQUEST_URI'],
43    $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? null,
44);
45
46// Compatibility
47if ($EXPL_LANG == '') { unset($EXPL_LANG); }
48