UB-Mannheim /
PalMA
| 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 'hi': |
||||||
| 57 | // Hindi. |
||||||
| 58 | $locale = 'hi_IN.UTF-8'; |
||||||
| 59 | break; |
||||||
| 60 | case 'it': |
||||||
| 61 | // Italian. |
||||||
| 62 | $locale = 'it_IT.UTF-8'; |
||||||
| 63 | break; |
||||||
| 64 | case 'ja': |
||||||
| 65 | // Japanese. |
||||||
| 66 | $locale = 'ja.UTF-8'; |
||||||
| 67 | break; |
||||||
| 68 | case 'kg': |
||||||
| 69 | // Kyrgyz. |
||||||
| 70 | $locale = 'kg_KG.UTF-8'; |
||||||
| 71 | break; |
||||||
| 72 | case 'lv': |
||||||
| 73 | // Latvian. |
||||||
| 74 | $locale = 'lv_LV.UTF-8'; |
||||||
| 75 | break; |
||||||
| 76 | case 'ru': |
||||||
| 77 | // Russian. |
||||||
| 78 | $locale = 'ru_RU.UTF-8'; |
||||||
| 79 | break; |
||||||
| 80 | case 'ur': |
||||||
| 81 | // Urdu. |
||||||
| 82 | $locale = 'ur_PK.UTF-8'; |
||||||
| 83 | break; |
||||||
| 84 | case 'zh': |
||||||
| 85 | // Chinese. |
||||||
| 86 | $locale = 'zh_CN.UTF-8'; |
||||||
| 87 | break; |
||||||
| 88 | default: |
||||||
| 89 | $locale = 'en_US.UTF-8'; |
||||||
| 90 | break; |
||||||
| 91 | } |
||||||
| 92 | //~ error_log("setlocale $locale"); |
||||||
| 93 | putenv("LANG=$locale"); |
||||||
| 94 | _setlocale(LC_MESSAGES, $locale); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 95 | _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
Loading history...
|
|||||||
| 96 | _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
Loading history...
|
|||||||
| 97 | _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
Loading history...
|
|||||||
| 98 | |||||||
| 99 | if ($unittest[__FILE__]) { |
||||||
| 100 | |||||||
| 101 | function testlocale($locale = "") |
||||||
| 102 | { |
||||||
| 103 | if ($locale != "") { |
||||||
| 104 | _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
Loading history...
|
|||||||
| 105 | } |
||||||
| 106 | 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
Loading history...
|
|||||||
| 107 | } |
||||||
| 108 | |||||||
| 109 | // Run unit test. |
||||||
| 110 | |||||||
| 111 | 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
Loading history...
|
|||||||
| 112 | print "locale '$locale' is not supported on your system, using custom gettext implementation.\n"; |
||||||
| 113 | } else { |
||||||
| 114 | print "locale '$locale' is supported on your system, using native gettext implementation.\n"; |
||||||
| 115 | } |
||||||
| 116 | |||||||
| 117 | testlocale(); |
||||||
| 118 | testlocale('sq_AL.UTF-8'); |
||||||
| 119 | testlocale('ar.UTF-8'); |
||||||
| 120 | testlocale('de_DE.UTF-8'); |
||||||
| 121 | testlocale('el_GR.UTF-8'); |
||||||
| 122 | testlocale('en_US.UTF-8'); |
||||||
| 123 | testlocale('es_ES.UTF-8'); |
||||||
| 124 | testlocale('fr_FR.UTF-8'); |
||||||
| 125 | testlocale('hi_IN.UTF-8'); |
||||||
| 126 | testlocale('it_IT.UTF-8'); |
||||||
| 127 | testlocale('ja.UTF-8'); |
||||||
| 128 | testlocale('kg_KG.UTF-8'); |
||||||
| 129 | testlocale('lv_LV.UTF-8'); |
||||||
| 130 | testlocale('ru_RU.UTF-8'); |
||||||
| 131 | testlocale('ur_PK.UTF-8'); |
||||||
| 132 | testlocale('zh_CN.UTF-8'); |
||||||
| 133 | } |
||||||
| 134 |