FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
i18n.php
1 <?php
2 /***********************************************************
3  Copyright (C) 2010-2011 Stefan Schroeder as a part of the FOSSOLOGY project.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
19 $locale = "";
20 
21 // We're interested only in language, not country.
22 // I do not bother to do a meticulous parsing of the
23 // accepted languages (RFC 2616), therefore we simply rip of the first
24 // two characters and hope that this is a known language
25 // according to ISO 639-1. If not: Bad luck.
26 if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
27  $browser_lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
28  $lang = substr($browser_lang, 0, 2);
29 } else {
30  $lang = '';
31 }
32 
33 // Set locale depending on language.
34 switch ($lang) {
35  // Add new languages below HERE!
36  case ("de"):
37  $locale = "de_DE";
38  break;
39  // Add new languages above HERE!
40  default: // Nothing to do for 'unknown locale'?
41 }
42 
43 if (isset($_GET["locale"])) {
44  $locale = $_GET["locale"];
45 }
46 putenv("LC_ALL=$locale");
47 setlocale(LC_ALL, $locale);
48 bindtextdomain("messages", "./locale");
49 textdomain("messages");
50 //print("Browser says: $browser_lang, Your language is $lang, your locale is $locale");
51