1 | <?php |
||
2 | // This file is part of BOINC. |
||
3 | // http://boinc.berkeley.edu |
||
4 | // Copyright (C) 2008 University of California |
||
5 | // |
||
6 | // BOINC is free software; you can redistribute it and/or modify it |
||
7 | // under the terms of the GNU Lesser General Public License |
||
8 | // as published by the Free Software Foundation, |
||
9 | // either version 3 of the License, or (at your option) any later version. |
||
10 | // |
||
11 | // BOINC is distributed in the hope that it will be useful, |
||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
14 | // See the GNU Lesser General Public License for more details. |
||
15 | // |
||
16 | // You should have received a copy of the GNU Lesser General Public License |
||
17 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
18 | |||
19 | // support for page-level translation |
||
20 | // Some of this should be merged with translation.inc |
||
21 | |||
22 | function get_lang_list() { |
||
23 | if (isset($_COOKIE['lang'])){ |
||
24 | $language_string = $_COOKIE['lang'].","; |
||
25 | } else { |
||
26 | $language_string = ''; |
||
27 | } |
||
28 | if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) { |
||
29 | $language_string .= strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]); |
||
30 | } |
||
31 | $client_languages = explode(",",$language_string); |
||
32 | |||
33 | $lang_list = array(); |
||
34 | for ($i=0; $i<sizeof($client_languages); $i++) { |
||
0 ignored issues
–
show
|
|||
35 | if ((strlen($client_languages[$i])>2) |
||
36 | && (substr($client_languages[$i],2,1)=="_" || substr($client_languages[$i],2,1)=="-")) |
||
37 | { |
||
38 | // If this is defined as primary-secondary, represent it as xx_YY |
||
39 | // |
||
40 | $language = substr( |
||
41 | $client_languages[$i],0,2)."_".strtoupper(substr($client_languages[$i],3,2) |
||
42 | ); |
||
43 | $lang_list[] = $language; |
||
44 | |||
45 | // And also check for the primary language |
||
46 | // |
||
47 | $language = substr($client_languages[$i],0,2); |
||
48 | $lang_list[] = $language; |
||
49 | } else { |
||
50 | // else just use xx |
||
51 | // |
||
52 | $language = substr($client_languages[$i],0,2); |
||
53 | $lang_list[] = $language; |
||
54 | } |
||
55 | } |
||
56 | return $lang_list; |
||
57 | } |
||
58 | |||
59 | function find_translation($file) { |
||
60 | $lang_list = get_lang_list(); |
||
61 | foreach ($lang_list as $lang) { |
||
62 | $path = "language_dirs/$lang/$file"; |
||
63 | if (file_exists($path)) { |
||
64 | readfile($path); |
||
65 | exit(); |
||
0 ignored issues
–
show
|
|||
66 | } |
||
67 | } |
||
68 | } |
||
69 | |||
70 | |||
71 | ?> |
||
72 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: