Passed
Push — master ( eb69c9...fcad25 )
by Stefan
54s queued 10s
created
Labels
Severity
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
} elseif (isset($_SESSION['lang'])) {
21
    // Get language from session data.
22
    $locale = $_SESSION['lang'];
23
} elseif (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 = 'sq_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 'ja':
57
        // Japanese.
58
        $locale = 'ja.UTF-8';
59
        break;
60
    case 'lv':
61
        // Latvian.
62
        $locale = 'lv_LV.UTF-8';
63
        break;
64
    case 'ru':
65
        // Russian.
66
        $locale = 'ru_RU.UTF-8';
67
        break;
68
    case 'ur':
69
        // Urdu.
70
        $locale = 'ur_PK.UTF-8';
71
        break;
72
    case 'zh':
73
        // Chinese.
74
        $locale = 'zh_CN.UTF-8';
75
        break;
76
    default:
77
        $locale = 'en_US.UTF-8';
78
        break;
79
}
80
    //~ error_log("setlocale $locale");
81
    putenv("LANG=$locale");
82
    _setlocale(LC_MESSAGES, $locale);
0 ignored issues
show
The function _setlocale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
    /** @scrutinizer ignore-call */ 
83
    _setlocale(LC_MESSAGES, $locale);
Loading history...
83
    _bindtextdomain('palma', 'locale');
0 ignored issues
show
The function _bindtextdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
    /** @scrutinizer ignore-call */ 
84
    _bindtextdomain('palma', 'locale');
Loading history...
84
    _bind_textdomain_codeset('palma', 'UTF-8');
0 ignored issues
show
The function _bind_textdomain_codeset was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
    /** @scrutinizer ignore-call */ 
85
    _bind_textdomain_codeset('palma', 'UTF-8');
Loading history...
85
    _textdomain('palma');
0 ignored issues
show
The function _textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
    /** @scrutinizer ignore-call */ 
86
    _textdomain('palma');
Loading history...
86
87
if ($unittest[__FILE__]) {
88
89
    function testlocale($locale = "")
90
    {
91
        if ($locale != "") {
92
            _setlocale(LC_MESSAGES, $locale);
0 ignored issues
show
The function _setlocale was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
            /** @scrutinizer ignore-call */ 
93
            _setlocale(LC_MESSAGES, $locale);
Loading history...
93
        }
94
        error_log(sprintf('%-12s ', ($locale ? $locale : 'default') . ':') . __('Screen section'));
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        error_log(sprintf('%-12s ', ($locale ? $locale : 'default') . ':') . /** @scrutinizer ignore-call */ __('Screen section'));
Loading history...
95
    }
96
97
    // Run unit test.
98
99
    if (locale_emulation()) {
0 ignored issues
show
The function locale_emulation was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
    if (/** @scrutinizer ignore-call */ locale_emulation()) {
Loading history...
100
        print "locale '$locale' is not supported on your system, using custom gettext implementation.\n";
101
    } else {
102
        print "locale '$locale' is supported on your system, using native gettext implementation.\n";
103
    }
104
105
    testlocale();
106
    testlocale('sq_AL.UTF-8');
107
    testlocale('ar.UTF-8');
108
    testlocale('de_DE.UTF-8');
109
    testlocale('en_US.UTF-8');
110
    testlocale('es_ES.UTF-8');
111
    testlocale('fr_FR.UTF-8');
112
    testlocale('it_IT.UTF-8');
113
    testlocale('ja.UTF-8');
114
    testlocale('lv_LV.UTF-8');
115
    testlocale('ru_RU.UTF-8');
116
    testlocale('ur_PK.UTF-8');
117
    testlocale('zh_CN.UTF-8');
118
}
119