ENHANCEMENT Making Date->Ago() translatable

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@68761 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-12-13 22:51:22 +00:00 committed by Sam Minnee
parent 345ec4e885
commit 76f4af842e
2 changed files with 31 additions and 6 deletions

View File

@ -95,10 +95,27 @@ class Date extends DBField {
*/
function Ago() {
if($this->value) {
if(time() < strtotime($this->value)) $agoWord = _t("Date.AWAY", " away");
else $agoWord = _t("Date.AGO", " ago");
return $this->TimeDiff() . ' ' . $agoWord;
if(time() > strtotime($this->value)) {
return sprintf(
_t(
'Date.TIMEDIFFAGO',
"%s ago",
PR_MEDIUM,
'Natural language time difference, e.g. 2 hours ago'
),
$this->TimeDiff()
);
} else {
return sprintf(
_t(
'Date.TIMEDIFFAWAY',
"%s away",
PR_MEDIUM,
'Natural language time difference, e.g. 2 hours away'
),
$this->TimeDiff()
);
}
}
}

View File

@ -126,8 +126,6 @@ $lang['en_US']['DataObject']['SINGULARNAME'] = array(
50,
'Singular name of the object, used in dropdowns and to generally identify a single object in the interface'
);
$lang['en_US']['Date']['AGO'] = ' ago';
$lang['en_US']['Date']['AWAY'] = ' away';
$lang['en_US']['Date']['DAY'] = ' day';
$lang['en_US']['Date']['DAYS'] = ' days';
$lang['en_US']['Date']['HOUR'] = ' hour';
@ -138,6 +136,16 @@ $lang['en_US']['Date']['MONTH'] = ' month';
$lang['en_US']['Date']['MONTHS'] = ' months';
$lang['en_US']['Date']['SEC'] = ' sec';
$lang['en_US']['Date']['SECS'] = ' secs';
$lang['en_US']['Date']['TIMEDIFFAGO'] = array(
'%s ago',
PR_MEDIUM,
'Natural language time difference, e.g. 2 hours ago'
);
$lang['en_US']['Date']['TIMEDIFFAWAY'] = array(
'%s away',
PR_MEDIUM,
'Natural language time difference, e.g. 2 hours away'
);
$lang['en_US']['Date']['YEAR'] = ' year';
$lang['en_US']['Date']['YEARS'] = ' years';
$lang['en_US']['DateField']['NOTSET'] = 'not set';