FOSSology  4.4.0
Open Source License Compliance by Open Source Software
i18n.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010-2011 Stefan Schroeder
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 $locale = "";
9 
10 // We're interested only in language, not country.
11 // I do not bother to do a meticulous parsing of the
12 // accepted languages (RFC 2616), therefore we simply rip of the first
13 // two characters and hope that this is a known language
14 // according to ISO 639-1. If not: Bad luck.
15 if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
16  $browser_lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
17  $lang = substr($browser_lang, 0, 2);
18 } else {
19  $lang = '';
20 }
21 
22 // Set locale depending on language.
23 switch ($lang) {
24  // Add new languages below HERE!
25  case ("de"):
26  $locale = "de_DE";
27  break;
28  // Add new languages above HERE!
29  default: // Nothing to do for 'unknown locale'?
30 }
31 
32 if (isset($_GET["locale"])) {
33  $locale = $_GET["locale"];
34 }
35 putenv("LC_ALL=$locale");
36 setlocale(LC_ALL, $locale);
37 bindtextdomain("messages", "./locale");
38 textdomain("messages");
39 //print("Browser says: $browser_lang, Your language is $lang, your locale is $locale");
40