Index: trunk/phase3/tests/phpunit/languages/LanguageTest.php |
— | — | @@ -21,27 +21,42 @@ |
22 | 22 | } |
23 | 23 | |
24 | 24 | /** @dataProvider provideFormattableTimes */ |
25 | | - function testFormatTimePeriod( $seconds, $avoid, $expected, $desc ) { |
26 | | - $this->assertEquals( $expected, $this->lang->formatTimePeriod( $seconds, $avoid ), $desc ); |
| 25 | + function testFormatTimePeriod( $seconds, $avoid, $noAbbrevs, $expected, $desc ) { |
| 26 | + $this->assertEquals( $expected, $this->lang->formatTimePeriod( $seconds, $avoid, $noAbbrevs ), $desc ); |
27 | 27 | } |
28 | 28 | |
29 | 29 | function provideFormattableTimes() { |
30 | 30 | return array( |
31 | | - array( 9.45, false, '9.5s', 'formatTimePeriod() rounding (<10s)' ), |
32 | | - array( 9.95, false, '10s', 'formatTimePeriod() rounding (<10s)' ), |
33 | | - array( 59.55, false, '1m 0s', 'formatTimePeriod() rounding (<60s)' ), |
34 | | - array( 119.55, false, '2m 0s', 'formatTimePeriod() rounding (<1h)' ), |
35 | | - array( 3599.55, false, '1h 0m 0s', 'formatTimePeriod() rounding (<1h)' ), |
36 | | - array( 7199.55, false, '2h 0m 0s', 'formatTimePeriod() rounding (>=1h)' ), |
37 | | - array( 7199.55, 'avoidseconds', '2h 0m', 'formatTimePeriod() rounding (>=1h), avoidseconds' ), |
38 | | - array( 7199.55, 'avoidminutes', '2h 0m', 'formatTimePeriod() rounding (>=1h), avoidminutes' ), |
39 | | - array( 172799.55, 'avoidseconds', '48h 0m', 'formatTimePeriod() rounding (=48h), avoidseconds' ), |
40 | | - array( 259199.55, 'avoidminutes', '3d 0h', 'formatTimePeriod() rounding (>48h), avoidminutes' ), |
41 | | - array( 176399.55, 'avoidseconds', '2d 1h 0m', 'formatTimePeriod() rounding (>48h), avoidseconds' ), |
42 | | - array( 176399.55, 'avoidminutes', '2d 1h', 'formatTimePeriod() rounding (>48h), avoidminutes' ), |
43 | | - array( 259199.55, 'avoidseconds', '3d 0h 0m', 'formatTimePeriod() rounding (>48h), avoidseconds' ), |
44 | | - array( 172801.55, 'avoidseconds', '2d 0h 0m', 'formatTimePeriod() rounding, (>48h), avoidseconds' ), |
45 | | - array( 176460.55, false, '2d 1h 1m 1s', 'formatTimePeriod() rounding, recursion, (>48h)' ), |
| 31 | + array( 9.45, false, false, '9.5s', 'formatTimePeriod() rounding (<10s)' ), |
| 32 | + array( 9.45, false, 'noabbrevs', '9.5 seconds', 'formatTimePeriod() rounding (<10s)' ), |
| 33 | + array( 9.95, false, false, '10s', 'formatTimePeriod() rounding (<10s)' ), |
| 34 | + array( 9.95, false, 'noabbrevs', '10 seconds', 'formatTimePeriod() rounding (<10s)' ), |
| 35 | + array( 59.55, false, false, '1m 0s', 'formatTimePeriod() rounding (<60s)' ), |
| 36 | + array( 59.55, false, 'noabbrevs', '1 minute 0 seconds', 'formatTimePeriod() rounding (<60s)' ), |
| 37 | + array( 119.55, false, false, '2m 0s', 'formatTimePeriod() rounding (<1h)' ), |
| 38 | + array( 119.55, false, 'noabbrevs', '2 minutes 0 seconds', 'formatTimePeriod() rounding (<1h)' ), |
| 39 | + array( 3599.55, false, false, '1h 0m 0s', 'formatTimePeriod() rounding (<1h)' ), |
| 40 | + array( 3599.55, false, 'noabbrevs', '1 hour 0 minutes 0 seconds', 'formatTimePeriod() rounding (<1h)' ), |
| 41 | + array( 7199.55, false, false, '2h 0m 0s', 'formatTimePeriod() rounding (>=1h)' ), |
| 42 | + array( 7199.55, false, 'noabbrevs', '2 hours 0 minutes 0 seconds', 'formatTimePeriod() rounding (>=1h)' ), |
| 43 | + array( 7199.55, 'avoidseconds', false, '2h 0m', 'formatTimePeriod() rounding (>=1h), avoidseconds' ), |
| 44 | + array( 7199.55, 'avoidseconds', 'noabbrevs', '2 hours 0 minutes', 'formatTimePeriod() rounding (>=1h), avoidseconds' ), |
| 45 | + array( 7199.55, 'avoidminutes', false, '2h 0m', 'formatTimePeriod() rounding (>=1h), avoidminutes' ), |
| 46 | + array( 7199.55, 'avoidminutes', 'noabbrevs', '2 hours 0 minutes', 'formatTimePeriod() rounding (>=1h), avoidminutes' ), |
| 47 | + array( 172799.55, 'avoidseconds', false, '48h 0m', 'formatTimePeriod() rounding (=48h), avoidseconds' ), |
| 48 | + array( 172799.55, 'avoidseconds', 'noabbrevs', '48 hours 0 minutes', 'formatTimePeriod() rounding (=48h), avoidseconds' ), |
| 49 | + array( 259199.55, 'avoidminutes', false, '3d 0h', 'formatTimePeriod() rounding (>48h), avoidminutes' ), |
| 50 | + array( 259199.55, 'avoidminutes', 'noabbrevs', '3 days 0 hours', 'formatTimePeriod() rounding (>48h), avoidminutes' ), |
| 51 | + array( 176399.55, 'avoidseconds', false, '2d 1h 0m', 'formatTimePeriod() rounding (>48h), avoidseconds' ), |
| 52 | + array( 176399.55, 'avoidseconds', 'noabbrevs', '2 days 1 hour 0 minutes', 'formatTimePeriod() rounding (>48h), avoidseconds' ), |
| 53 | + array( 176399.55, 'avoidminutes', false, '2d 1h', 'formatTimePeriod() rounding (>48h), avoidminutes' ), |
| 54 | + array( 176399.55, 'avoidminutes', 'noabbrevs', '2 days 1 hour', 'formatTimePeriod() rounding (>48h), avoidminutes' ), |
| 55 | + array( 259199.55, 'avoidseconds', false, '3d 0h 0m', 'formatTimePeriod() rounding (>48h), avoidseconds' ), |
| 56 | + array( 259199.55, 'avoidseconds', 'noabbrevs', '3 days 0 hours 0 minutes', 'formatTimePeriod() rounding (>48h), avoidseconds' ), |
| 57 | + array( 172801.55, 'avoidseconds', false, '2d 0h 0m', 'formatTimePeriod() rounding, (>48h), avoidseconds' ), |
| 58 | + array( 172801.55, 'avoidseconds', 'noabbrevs', '2 days 0 hours 0 minutes', 'formatTimePeriod() rounding, (>48h), avoidseconds' ), |
| 59 | + array( 176460.55, false, false, '2d 1h 1m 1s', 'formatTimePeriod() rounding, recursion, (>48h)' ), |
| 60 | + array( 176460.55, false, 'noabbrevs', '2 days 1 hour 1 minute 1 second', 'formatTimePeriod() rounding, recursion, (>48h)' ), |
46 | 61 | ); |
47 | 62 | |
48 | 63 | } |
Index: trunk/phase3/languages/messages/MessagesEn.php |
— | — | @@ -3656,10 +3656,15 @@ |
3657 | 3657 | |
3658 | 3658 | # Video information, used by Language::formatTimePeriod() to format lengths in the above messages |
3659 | 3659 | 'video-dims' => '$1, $2×$3', # only translate this message to other languages if you have to change it |
3660 | | -'seconds-abbrev' => 's', # only translate this message to other languages if you have to change it |
3661 | | -'minutes-abbrev' => 'm', # only translate this message to other languages if you have to change it |
3662 | | -'hours-abbrev' => 'h', # only translate this message to other languages if you have to change it |
3663 | | -'days-abbrev' => 'd', # only translate this message to other languages if you have to change it |
| 3660 | +'seconds-abbrev' => '$1s', # only translate this message to other languages if you have to change it |
| 3661 | +'minutes-abbrev' => '$1m', # only translate this message to other languages if you have to change it |
| 3662 | +'hours-abbrev' => '$1h', # only translate this message to other languages if you have to change it |
| 3663 | +'days-abbrev' => '$1d', # only translate this message to other languages if you have to change it |
| 3664 | +'seconds' => '{{PLURAL:$1|$1 second|$1 seconds}}', |
| 3665 | +'minutes' => '{{PLURAL:$1|$1 minute|$1 minutes}}', |
| 3666 | +'hours' => '{{PLURAL:$1|$1 hour|$1 hours}}', |
| 3667 | +'days' => '{{PLURAL:$1|$1 day|$1 days}}', |
| 3668 | +'ago' => '$1 ago', |
3664 | 3669 | |
3665 | 3670 | # Bad image list |
3666 | 3671 | 'bad_image_list' => 'The format is as follows: |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -3552,15 +3552,20 @@ |
3553 | 3553 | * @param $format String Optional, one of ("avoidseconds","avoidminutes"): |
3554 | 3554 | * "avoidseconds" - don't mention seconds if $seconds >= 1 hour |
3555 | 3555 | * "avoidminutes" - don't mention seconds/minutes if $seconds > 48 hours |
| 3556 | + * @param $noAbbrevs Bool If true (or true-ish, recommend using 'noabbrevs' for clarity), use 'seconds' and friends instead of 'seconds-abbrev' and friends |
3556 | 3557 | * @return string |
3557 | 3558 | */ |
3558 | | - function formatTimePeriod( $seconds, $format = false ) { |
| 3559 | + function formatTimePeriod( $seconds, $format = false, $noAbbrevs = false ) { |
| 3560 | + $secondsMsg = wfMessage( $noAbbrevs ? 'seconds' : 'seconds-abbrev' )->inLanguage( $this ); |
| 3561 | + $minutesMsg = wfMessage( $noAbbrevs ? 'minutes' : 'minutes-abbrev' )->inLanguage( $this ); |
| 3562 | + $hoursMsg = wfMessage( $noAbbrevs ? 'hours' : 'hours-abbrev' )->inLanguage( $this ); |
| 3563 | + $daysMsg = wfMessage( $noAbbrevs ? 'days' : 'days-abbrev' )->inLanguage( $this ); |
3559 | 3564 | if ( round( $seconds * 10 ) < 100 ) { |
3560 | 3565 | $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ); |
3561 | | - $s .= $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3566 | + $s = $secondsMsg->params( $s )->text(); |
3562 | 3567 | } elseif ( round( $seconds ) < 60 ) { |
3563 | 3568 | $s = $this->formatNum( round( $seconds ) ); |
3564 | | - $s .= $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3569 | + $s = $secondsMsg->params( $s )->text(); |
3565 | 3570 | } elseif ( round( $seconds ) < 3600 ) { |
3566 | 3571 | $minutes = floor( $seconds / 60 ); |
3567 | 3572 | $secondsPart = round( fmod( $seconds, 60 ) ); |
— | — | @@ -3568,9 +3573,9 @@ |
3569 | 3574 | $secondsPart = 0; |
3570 | 3575 | $minutes++; |
3571 | 3576 | } |
3572 | | - $s = $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3577 | + $s = $minutesMsg->params( $this->formatNum( $minutes ) )->text(); |
3573 | 3578 | $s .= ' '; |
3574 | | - $s .= $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3579 | + $s .= $secondsMsg->params( $this->formatNum( $secondsPart ) )->text(); |
3575 | 3580 | } elseif ( round( $seconds ) <= 2 * 86400 ) { |
3576 | 3581 | $hours = floor( $seconds / 3600 ); |
3577 | 3582 | $minutes = floor( ( $seconds - $hours * 3600 ) / 60 ); |
— | — | @@ -3583,12 +3588,11 @@ |
3584 | 3589 | $minutes = 0; |
3585 | 3590 | $hours++; |
3586 | 3591 | } |
3587 | | - $s = $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3592 | + $s = $hoursMsg->params( $this->formatNum( $hours ) )->text(); |
3588 | 3593 | $s .= ' '; |
3589 | | - $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3594 | + $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text(); |
3590 | 3595 | if ( !in_array( $format, array( 'avoidseconds', 'avoidminutes' ) ) ) { |
3591 | | - $s .= ' ' . $this->formatNum( $secondsPart ) . |
3592 | | - $this->getMessageFromDB( 'seconds-abbrev' ); |
| 3596 | + $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text(); |
3593 | 3597 | } |
3594 | 3598 | } else { |
3595 | 3599 | $days = floor( $seconds / 86400 ); |
— | — | @@ -3598,9 +3602,9 @@ |
3599 | 3603 | $hours = 0; |
3600 | 3604 | $days++; |
3601 | 3605 | } |
3602 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3606 | + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); |
3603 | 3607 | $s .= ' '; |
3604 | | - $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3608 | + $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text(); |
3605 | 3609 | } elseif ( $format === 'avoidseconds' ) { |
3606 | 3610 | $hours = floor( ( $seconds - $days * 86400 ) / 3600 ); |
3607 | 3611 | $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 ); |
— | — | @@ -3612,15 +3616,15 @@ |
3613 | 3617 | $hours = 0; |
3614 | 3618 | $days++; |
3615 | 3619 | } |
3616 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3620 | + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); |
3617 | 3621 | $s .= ' '; |
3618 | | - $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); |
| 3622 | + $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text(); |
3619 | 3623 | $s .= ' '; |
3620 | | - $s .= $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); |
| 3624 | + $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text(); |
3621 | 3625 | } else { |
3622 | | - $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ); |
| 3626 | + $s = $daysMsg->params( $this->formatNum( $days ) )->text(); |
3623 | 3627 | $s .= ' '; |
3624 | | - $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format ); |
| 3628 | + $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format, $noAbbrevs ); |
3625 | 3629 | } |
3626 | 3630 | } |
3627 | 3631 | return $s; |