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 if (isset ($translations[$lang]) and isset($translations[$lang][$str])) {
15 $res = $translations[$lang][$str];
17 if (!isset ($res) || strlen ($res) == 0) {
24 function parse_accept_language () {
26 $possibilities = array();
27 if (isset ($_SERVER ['HTTP_ACCEPT_LANGUAGE'])) {
28 // set to lower case now
29 $accepts = explode (',',
30 strtolower ($_SERVER ['HTTP_ACCEPT_LANGUAGE']));
31 foreach ($accepts as $acc) {
32 if (preg_match ('/^\s*([a-zA-Z]+)(-[a-zA-Z]+)?\s*$/', $acc, $matches)) {
33 $possibilities [$matches [1]] = 1.0;
35 if (preg_match ('/^\s*([a-zA-Z]+)(-[a-zA-Z]+)?\s*;\s*q\s*=\s*([0-9\.]+)\s*$/',
37 $val = floatval ($matches [3]);
41 $ceil = (isset ($possibilities[$matches[1]]))? $possibilities[$matches[1]]: 0;
42 $possibilities [$matches [1]] = max ($val, $ceil);
45 arsort ($possibilities);
46 foreach ($possibilities as $lang => $value) {
47 if (isset ($translations [$lang])) {
52 return "en"; // nothing found; default to english
55 function other_languages ($current_lang) {
56 $script = pathinfo ($_SERVER ["SCRIPT_NAME"], PATHINFO_FILENAME);
57 $dotpos = strpos ($script, '.');
58 if ($dotpos !== false) {
59 $script = substr ($script, 0, $dotpos);
64 foreach ($translations as $lang => $obj) {
65 $lang_name = $obj ["_language_name"];
66 if ($lang == $current_lang) {
67 array_push ($links, "<a>$lang_name</a>");
69 array_push ($links, "<a href=\"$script.$lang.php\" title=\"$lang_name\" lang=\"$lang\" hreflang=\"$lang\">$lang_name</a>");
72 echo "<div id=\"other-language\">" . join("", $links) . "</div>\n";
76 foreach (scandir ("inc/i10n/") as $entry) {
77 if (is_dir ("inc/i10n/$entry") && ($entry [0] != ".")) {
78 $target = "inc/i10n/$entry/syp.php";
79 if (is_file ($target)) {
86 $fname = pathinfo ($_SERVER ["SCRIPT_NAME"], PATHINFO_FILENAME);
87 $lang = ltrim (strstr ($fname, '.'), '.');
88 if ((!isset ($lang)) ||
89 (strlen ($lang) == 0) ||
90 (!isset ($translations [$lang]))) {
91 $lang = parse_accept_language ();