Passed
Push — master ( 545bfd...abc97e )
by Stefan
02:21
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 'el':
41
        // Greek.
42
        $locale = 'el_GR.UTF-8';
43
        break;
44
    case 'en':
45
        // English.
46
        $locale = 'en_US.UTF-8';
47
        break;
48
    case 'es':
49
        // Spanish.
50
        $locale = 'es_ES.UTF-8';
51
        break;
52
    case 'fr':
53
        // French.
54
        $locale = 'fr_FR.UTF-8';
55
        break;
56
    case 'it':
57
        // Italian.
58
        $locale = 'it_IT.UTF-8';
59
        break;
60
    case 'ja':
61
        // Japanese.
62
        $locale = 'ja.UTF-8';
63
        break;
64
    case 'lv':
65
        // Latvian.
66
        $locale = 'lv_LV.UTF-8';
67
        break;
68
    case 'ru':
69
        // Russian.
70
        $locale = 'ru_RU.UTF-8';
71
        break;
72
    case 'ur':
73
        // Urdu.
74
        $locale = 'ur_PK.UTF-8';
75
        break;
76
    case 'zh':
77
        // Chinese.
78
        $locale = 'zh_CN.UTF-8';
79
        break;
80
    default:
81
        $locale = 'en_US.UTF-8';
82
        break;
83
}
84
    //~ error_log("setlocale $locale");
85
    putenv("LANG=$locale");
86
    _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

86
    /** @scrutinizer ignore-call */ 
87
    _setlocale(LC_MESSAGES, $locale);
Loading history...
87
    _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

87
    /** @scrutinizer ignore-call */ 
88
    _bindtextdomain('palma', 'locale');
Loading history...
88
    _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

88
    /** @scrutinizer ignore-call */ 
89
    _bind_textdomain_codeset('palma', 'UTF-8');
Loading history...
89
    _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

89
    /** @scrutinizer ignore-call */ 
90
    _textdomain('palma');
Loading history...
90
91
if ($unittest[__FILE__]) {
92
93
    function testlocale($locale = "")
94
    {
95
        if ($locale != "") {
96
            _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

96
            /** @scrutinizer ignore-call */ 
97
            _setlocale(LC_MESSAGES, $locale);
Loading history...
97
        }
98
        error_log(sprintf('%-12s ', ($locale ? $locale : 'default') . ':') . addslashes(__('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

98
        error_log(sprintf('%-12s ', ($locale ? $locale : 'default') . ':') . addslashes(/** @scrutinizer ignore-call */ __('Screen section')));
Loading history...
99
    }
100
101
    // Run unit test.
102
103
    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

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