[horde] Setting date and time preferences
Jens Wahnes
wahnes at uni-koeln.de
Thu Apr 23 16:39:52 UTC 2015
On Thu, Apr 23 2015, at 15:09:57 +0200, Jens Wahnes wrote:
> I tried to use
>
> $currentlocale = $scope_ob->get("language");
>
> but that doesn't seem to work (there isn't any value set).
After a while, I found a way to work around this. Not a particular
beautiful way to do it, but it works. In case anyone else is
interested, here's the function I came up with to select the default
"24 hour clock" setting based on the current language (or the preferred
language, if set). Feel free to use it -- or better yet: improve it.
public function prefs_init($pref, $value, $username, $scope_ob)
{
// This hook receives the preference name, preference value, username, and
// the master scope object (Horde_Prefs_Scope) as parameters and uses the
// return value from the hook as the new preference value.
//
// Username will be null if the user is not authenticated.
$loglevel="DEBUG"; # available choices: ERR, DEBUG, NOTICE, INFO
Horde::log("prefs_init was called with these parameters: \$pref=$pref, \$value=$value, \$username=$username, \$scope_ob=".print_r($scope_ob,true), $loglevel);
if ( ($pref == 'twentyFour') && isset($username) ) {
Horde::log("prefs_init: I'm gonna get you one way ...", $loglevel);
$currentlocale = $scope_ob->get("language");
if ( ! ($currentlocale) ) {
Horde::log("prefs_init: ... or another", $loglevel);
$currentlocale = setlocale(LC_TIME, 0); // with second argument '0', it's not setlocale but getlocale, actually
}
Horde::log("prefs_init: \$currentlocale=$currentlocale", $loglevel);
if ( strlen($currentlocale) > 5 ) {
// not in pure ll_CC format, so throw away the rest, e.g. shorten 'de_DE.UTF-8' to 'de_DE'
$currentlocale = substr($currentlocale, 0, 5);
Horde::log("prefs_init: shortened \$currentlocale to $currentlocale", $loglevel);
}
$twelveHourLocales = array("ar_OM", "ar_SY", "en_US", "en_CA", "el_GR");
if (in_array($currentlocale, $twelveHourLocales)) {
Horde::log("Setting default 24-hour-clock pref to false because of $currentlocale locale", $loglevel);
return false;
}
else {
Horde::log("Default 24-hour-clock pref will be set to true because of $currentlocale locale", $loglevel);
return true;
}
}
return $value; // just as a safeguard
}
Jens
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
URL: <http://lists.horde.org/archives/horde/attachments/20150423/d4197718/attachment.bin>
More information about the horde
mailing list