Created a new folder in _templates to house site icons. Put the new RSS standard...
[elgg.git] / units / gettext / library.php
blobcee2c7b0d03d7e8165fabca64b663714659c3ee2
1 <?php
3 // If gettext isn't installed, define a function placeholder for gettext()
5 if (!function_exists("gettext")) {
6 function gettext($input) {
7 return $input;
9 define("gettext", false);
10 } else {
11 define("gettext", true);
14 // If gettext is installed, define path for languages, set language etc
15 if (gettext == true) {
17 // If default language isn't specified, it's English
18 if (!defined("locale")) {
19 define("locale", "en");
22 // If the user's browser hasn't set a language, set it to be the default locale
23 // If it has, create a list of languages in preference order
24 $list = array();
26 if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) || $_SERVER['HTTP_ACCEPT_LANGUAGE'] == "") {
27 $locale = strtolower(locale);
28 $list[] = $locale;
29 } else {
30 $locale = strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']);
31 $list = explode(",", $locale);
34 // If the locale isn't the default, set a new default language
35 // If the first choice is the right non-country-specific language, don't bother
36 // (kludge to allow a browser to default to "en", basically)
37 if (substr($list[0], 0, 2) != substr(locale, 0, 2)) {
38 // Bind the 'elgg' text domain to the languages directory
39 $textdomainpath = bindtextdomain ('elgg', path . 'languages');
40 // Set our current text domain to 'elgg'
41 textdomain ('elgg');
42 // Set locale to language_COUNTRY in preference order
43 if (sizeof($list) > 0) {
44 $newlist = array();
45 $extralist = array();
46 foreach ($list as $language) {
47 $language = explode(";", $language);
48 $language = $language[0];
49 $languageparts = explode("-", $language);
50 if ($languageparts[1]) {
51 // If the browser has given a 2-part language code, use it...
52 $newlist[] = $languageparts[0] . "_" . strtoupper($languageparts[1]);
53 // but also add the munged code to the end of the list, just in case.
54 // E.g. if user passes "de_AT", this will add "de_DE" to end of the list as a fallback.
55 $extralist[] = $languageparts[0] . "_" . strtoupper($languageparts[0]);
56 } else {
57 // Otherwise munge one from a 1-part code.
58 // NB. This is a flawed assumption, because not all languages have the same language
59 // and country codes: e.g. en_EN is not valid for English, and Danish is da_DK.
60 $newlist[] = $languageparts[0] . "_" . strtoupper($languageparts[0]);
63 $list = array_merge($newlist, $extralist);
65 // Add user locales to global configuration settings.
66 $CFG->userlocale = $list;
68 foreach($list as $languagecode) {
69 // Presumably we don't want to set locale to a language we don't have the .mo file for?
70 if (file_exists($textdomainpath . '/' . $languagecode . '/LC_MESSAGES/elgg.mo')) {
71 // Try UTF-8 version of the locale first.
72 if (setlocale(LC_MESSAGES, $languagecode.'.UTF-8', $languagecode)) {
73 setlocale(LC_TIME, $languagecode.'.UTF-8', $languagecode);
74 break;
79 // This is a UTF-8 application
80 bind_textdomain_codeset('elgg', 'UTF-8');