2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
5 $language_list = Array ();
7 function ptrans ($str) {
11 function trans ($str) {
12 global $translations, $lang;
14 $res = $translations[$lang][$str];
15 if (!isset ($res) || strlen ($res) == 0) {
22 function parse_accept_language () {
24 $possibilities = array();
25 if (isset ($_SERVER ['HTTP_ACCEPT_LANGUAGE'])) {
26 // set to lower case now
27 $accepts = explode (',',
28 strtolower ($_SERVER ['HTTP_ACCEPT_LANGUAGE']));
29 foreach ($accepts as $acc) {
30 if (preg_match ('/^\s*([a-zA-Z]+)(-[a-zA-Z]+)?\s*$/', $acc, $matches)) {
31 $possibilities [$matches [1]] = 1.0;
33 if (preg_match ('/^\s*([a-zA-Z]+)(-[a-zA-Z]+)?\s*;\s*q\s*=\s*([0-9\.]+)\s*$/',
35 $val = floatval ($matches [3]);
39 $possibilities [$matches [1]] = max ($val, $possibilities [$matches [1]]);
42 arsort ($possibilities);
43 foreach ($possibilities as $lang => $value) {
44 if (isset ($translations [$lang])) {
49 return "en"; // nothing found; default to english
52 function other_languages ($current_lang) {
53 $script = pathinfo ($_SERVER ["SCRIPT_NAME"], PATHINFO_FILENAME);
54 $dotpos = strpos ($script, '.');
55 if ($dotpos !== false) {
56 $script = substr ($script, 0, $dotpos);
61 foreach ($translations as $lang => $obj) {
62 $lang_name = $obj ["_language_name"];
63 if ($lang == $current_lang) {
64 array_push ($links, "<a>$lang_name</a>");
66 array_push ($links, "<a href=\"$script.$lang.php\" title=\"$lang_name\" lang=\"$lang\" hreflang=\"$lang\">$lang_name</a>");
69 echo "<div id=\"other-language\">" . join("", $links) . "</div>\n";
73 foreach (scandir ("inc/i10n/") as $entry) {
74 if (is_dir ("inc/i10n/$entry") && ($entry [0] != ".")) {
75 $target = "inc/i10n/$entry/syp.php";
76 if (is_file ($target)) {
83 $fname = pathinfo ($_SERVER ["SCRIPT_NAME"], PATHINFO_FILENAME);
84 $lang = ltrim (strstr ($fname, '.'), '.');
85 if ((!isset ($lang)) ||
86 (strlen ($lang) == 0) ||
87 (!isset ($translations [$lang]))) {
88 $lang = parse_accept_language ();