Browse the code
| Revision log Information on the revision | |
|---|---|
| Revision: | 282 (differences) |
| Author: | xbright |
| Log message: |
* Fixed a few bugs related to cache cleaning and the timeline * Fixed a bug in Locale class * Fixed a bug in bugs search |
| Change revision: | |
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php # This file is a part of CodingTeam. See <http://www.codingteam.net>. # Copyright (C) 2007-2009 CodingTeam (See AUTHORS and THANKS for details) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, version 3 only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. /** * @file * This file contains the Locale class * * Confront ISO 639-1 languages code to the system /usr/share/i18n/SUPPORTED in * order to get a reliable list of countries speaking that language. Also, get * informations about the usability of a locale with /etc/locale.gen. * Systems that doesn't use these files are also supported. */ /** * Locale class */ class Locale { function __construct() { $this->score = -2; if (file_exists('/usr/share/i18n/SUPPORTED')) $this->score ++; if (file_exists('/etc/locale.gen')) $this->score ++; } /** * getCountries * * Get a list of countries where the given lang exists. * @param $lang * The lang to search. * @return * The list of related countries. */ function getCountries($lang) { $regex = '!^'.$lang.'_([A-Z]+)$!'; $locales_dir = '/usr/share/i18n/locales/'; $countries = array(); if (is_dir($locales_dir)) { $valid_locales = glob($locales_dir.'*_*'); foreach ($valid_locales as $locale) { $locale_kaboum = explode('/', $locale); $locale_clean = $locale_kaboum[count($locale_kaboum) - 1]; if (preg_match($regex, $locale_clean, $country)) array_push($countries, $country[1]); } } else array_push($countries, strtoupper($lang)); return $countries; } /** * isSupported * * Test if a language/country couple is supported by the * system locales. * @param $locale * The language/country couple to test. * @return * The locale name if TRUE. */ function isSupported($locale) { // CodingTeam is running on a system that ask the administrator to // active each locale he wants to use (like Debian), so we test if // this locale is usable. if ($this->score == 0) { $supported_locales = file('/etc/locale.gen'); foreach($supported_locales as $supported_locale) if ($supported_locale[0] != '#' && mb_substr($supported_locale, 0, 17) == $locale.'.UTF-8 UTF-8') return $locale.'.UTF-8'; } // CodingTeam runs on a system that active all locales by default. else return $locale.'.UTF-8'; } } ?>

CodingTeam