Completed
Branch — master (f6660f)
by Stefan
02:22
created
1
<?php
2
3
// Copyright (C) 2014-2016 Universitätsbibliothek Mannheim
4
// See file LICENSE for license details.
5
6
// Test whether the script was called directly (used for unit test).
7
if (!isset($unittest)) {
8
    $unittest = array();
9
}
10
$unittest[__FILE__] = (sizeof(get_included_files()) == 1);
11
12
require_once('php-gettext/gettext.inc');
13
14
    // The default translations are in locale/en_US.UTF-8/LC_MESSAGES/palma.mo.
15
    $locale = '';
16
    if (isset($_REQUEST['lang'])) {
17
        // User requested language by URL parameter.
18
        $locale = $_REQUEST['lang'];
19
        $_SESSION['lang'] = $locale;
20
    } else if (isset($_SESSION['lang'])) {
21
        // Get language from session data.
22
        $locale = $_SESSION['lang'];
23
    } else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
24
        // Get language from browser settings.
25
        $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
26
    }
27
    switch (substr($locale, 0, 2)) {
28
    case 'al':
29
        // Albanian.
30
        $locale = 'al_AL.UTF-8';
31
        break;
32
    case 'ar':
33
        // Arabic.
34
        $locale = 'ar.UTF-8';
35
        break;
36
    case 'de':
37
        // German.
38
        $locale = 'de_DE.UTF-8';
39
        break;
40
    case 'en':
41
        // English.
42
        $locale = 'en_US.UTF-8';
43
        break;
44
    case 'es':
45
        // Spanish.
46
        $locale = 'es_ES.UTF-8';
47
        break;
48
    case 'fr':
49
        // French.
50
        $locale = 'fr_FR.UTF-8';
51
        break;
52
    case 'it':
53
        // Italian.
54
        $locale = 'it_IT.UTF-8';
55
        break;
56
    case 'lv':
57
        // Latvian.
58
        $locale = 'lv_LV.UTF-8';
59
        break;
60
    case 'ru':
61
        // Russian.
62
        $locale = 'ru_RU.UTF-8';
63
        break;
64
    case 'ur':
65
        // Urdu.
66
        $locale = 'ur_PK.UTF-8';
67
        break;
68
    case 'zh':
69
        // Chinese.
70
        $locale = 'zh_CN.UTF-8';
71
        break;
72
    default:
73
        $locale = 'en_US.UTF-8';
74
        break;
75
    }
76
    //~ error_log("setlocale $locale");
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
77
    putenv("LANG=$locale");
78
    _setlocale(LC_MESSAGES, $locale);
79
    _bindtextdomain('palma', 'locale');
80
    _bind_textdomain_codeset('palma', 'UTF-8');
81
    _textdomain('palma');
82
83
if ($unittest[__FILE__]) {
84
85
    function testlocale($locale = "")
86
    {
87
        if ($locale != "") {
88
            _setlocale(LC_MESSAGES, $locale);
89
        }
90
        error_log(sprintf('%-12s ', ($locale ? $locale : 'default') . ':') . __('Screen section'));
91
    }
92
93
    // Run unit test.
94
95
    if (locale_emulation()) {
96
        print "locale '$locale' is not supported on your system, using custom gettext implementation.\n";
97
    }
98
    else {
99
        print "locale '$locale' is supported on your system, using native gettext implementation.\n";
100
    }
101
102
    testlocale();
103
    testlocale('al_AL.UTF-8');
104
    testlocale('ar.UTF-8');
105
    testlocale('de_DE.UTF-8');
106
    testlocale('en_US.UTF-8');
107
    testlocale('es_ES.UTF-8');
108
    testlocale('fr_FR.UTF-8');
109
    testlocale('it_IT.UTF-8');
110
    testlocale('lv_LV.UTF-8');
111
    testlocale('ru_RU.UTF-8');
112
    testlocale('ur_PK.UTF-8');
113
    testlocale('zh_CN.UTF-8');
114
}
115