Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1841274
file_locale.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
file_locale.php
View Options
<?php
/*
+--------------------------------------------------------------------------+
| This file is part of the Kolab File API |
| |
| Copyright (C) 2011-2014, Kolab Systems AG |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
| Author: Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
class
file_locale
{
protected
static
$translation
=
array
();
/**
* Localization initialization.
*/
protected
function
locale_init
()
{
$language
=
$this
->
get_language
();
$LANG
=
array
();
if
(!
$language
)
{
$language
=
'en_US'
;
}
@
include
RCUBE_INSTALL_PATH
.
"/lib/locale/en_US.php"
;
if
(
$language
!=
'en_US'
)
{
@
include
RCUBE_INSTALL_PATH
.
"/lib/locale/$language.php"
;
}
setlocale
(
LC_ALL
,
$language
.
'.utf8'
,
$language
.
'UTF-8'
,
'en_US.utf8'
,
'en_US.UTF-8'
);
self
::
$translation
=
$LANG
;
}
/**
* Returns system language (locale) setting.
*
* @return string Language code
*/
protected
function
get_language
()
{
$aliases
=
array
(
'de'
=>
'de_DE'
,
'en'
=>
'en_US'
,
'pl'
=>
'pl_PL'
,
);
// UI language
$langs
=
!
empty
(
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
])
?
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
]
:
''
;
$langs
=
explode
(
','
,
$langs
);
if
(!
empty
(
$_SESSION
[
'user'
])
&&
!
empty
(
$_SESSION
[
'user'
][
'language'
]))
{
array_unshift
(
$langs
,
$_SESSION
[
'user'
][
'language'
]);
}
while
(
$lang
=
array_shift
(
$langs
))
{
$lang
=
explode
(
';'
,
$lang
);
$lang
=
$lang
[
0
];
$lang
=
str_replace
(
'-'
,
'_'
,
$lang
);
if
(
file_exists
(
RCUBE_INSTALL_PATH
.
"/lib/locale/$lang.php"
))
{
return
$lang
;
}
if
(
isset
(
$aliases
[
$lang
])
&&
(
$alias
=
$aliases
[
$lang
])
&&
file_exists
(
RCUBE_INSTALL_PATH
.
"/lib/locale/$alias.php"
)
)
{
return
$alias
;
}
}
return
null
;
}
/**
* Returns translation of defined label/message.
*
* @return string Translated string.
*/
public
static
function
translate
()
{
$args
=
func_get_args
();
if
(
is_array
(
$args
[
0
]))
{
$args
=
$args
[
0
];
}
$label
=
$args
[
0
];
if
(
isset
(
self
::
$translation
[
$label
]))
{
$content
=
trim
(
self
::
$translation
[
$label
]);
}
else
{
$content
=
$label
;
}
for
(
$i
=
1
,
$len
=
count
(
$args
);
$i
<
$len
;
$i
++)
{
$content
=
str_replace
(
'$'
.
$i
,
$args
[
$i
],
$content
);
}
return
$content
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Aug 25, 2:40 PM (18 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
257667
Default Alt Text
file_locale.php (3 KB)
Attached To
Mode
R26 chwala
Attached
Detach File
Event Timeline
Log In to Comment