Skip to content
This repository

Fix issue 1663: wrong i18n usage in TimeHelper #65

Merged
merged 1 commit into from almost 3 years ago

2 participants

Mariano Iglesias José Lorenzo Rodríguez
Mariano Iglesias

Fixing issue with wrong internationalization of time ago expressions in TimeHelper. Fixes #1663

José Lorenzo Rodríguez lorenzo referenced this pull request from a commit April 29, 2011
José Lorenzo Rodríguez Merged pull request #65 from English360/i1663.
Fix issue 1663: wrong i18n usage in TimeHelper
10d735f
José Lorenzo Rodríguez lorenzo merged commit 10d735f into from April 29, 2011
José Lorenzo Rodríguez lorenzo closed this April 29, 2011
José Lorenzo Rodríguez
Owner

Thanks, that is indeed the correct way of doing it... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 29, 2011
Mariano Iglesias Fixing issue with wrong internationalization of time ago expressions …
…in TimeHelper. Fixes #1663
cc5670a
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 18 additions and 18 deletions. Show diff stats Hide diff stats

  1. 36  cake/libs/view/helpers/time.php
36  cake/libs/view/helpers/time.php
@@ -33,7 +33,7 @@ class TimeHelper extends AppHelper {
33 33
  * Converts a string representing the format for the function strftime and returns a
34 34
  * windows safe and i18n aware format.
35 35
  *
36  
- * @param string $format Format with specifiers for strftime function. 
  36
+ * @param string $format Format with specifiers for strftime function.
37 37
  *    Accepts the special specifier %S which mimics th modifier S for date()
38 38
  * @param string UNIX timestamp
39 39
  * @return string windows safe and date() function compatible format for strftime
@@ -343,7 +343,7 @@ function isThisYear($dateString, $userOffset = null) {
343 343
  * @return boolean True if datetime string was yesterday
344 344
  * @access public
345 345
  * @link http://book.cakephp.org/view/1472/Testing-Time
346  
- * 
  346
+ *
347 347
  */
348 348
 	function wasYesterday($dateString, $userOffset = null) {
349 349
 		$date = $this->fromString($dateString, $userOffset);
@@ -589,33 +589,33 @@ function timeAgoInWords($dateTime, $options = array()) {
589 589
 		} else {
590 590
 			if ($years > 0) {
591 591
 				// years and months and days
592  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $years . ' ' . __n('year', 'years', $years, true);
593  
-				$relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . $months . ' ' . __n('month', 'months', $months, true) : '';
594  
-				$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true) : '';
595  
-				$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
  592
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d year', '%d years', $years, true), $years);
  593
+				$relativeDate .= $months > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d month', '%d months', $months, true), $months) : '';
  594
+				$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks) : '';
  595
+				$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
596 596
 			} elseif (abs($months) > 0) {
597 597
 				// months, weeks and days
598  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $months . ' ' . __n('month', 'months', $months, true);
599  
-				$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true) : '';
600  
-				$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
  598
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d month', '%d months', $months, true), $months);
  599
+				$relativeDate .= $weeks > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks) : '';
  600
+				$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
601 601
 			} elseif (abs($weeks) > 0) {
602 602
 				// weeks and days
603  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $weeks . ' ' . __n('week', 'weeks', $weeks, true);
604  
-				$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true) : '';
  603
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d week', '%d weeks', $weeks, true), $weeks);
  604
+				$relativeDate .= $days > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days) : '';
605 605
 			} elseif (abs($days) > 0) {
606 606
 				// days and hours
607  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $days . ' ' . __n('day', 'days', $days, true);
608  
-				$relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . $hours . ' ' . __n('hour', 'hours', $hours, true) : '';
  607
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d day', '%d days', $days, true), $days);
  608
+				$relativeDate .= $hours > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d hour', '%d hours', $hours, true), $hours) : '';
609 609
 			} elseif (abs($hours) > 0) {
610 610
 				// hours and minutes
611  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $hours . ' ' . __n('hour', 'hours', $hours, true);
612  
-				$relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . $minutes . ' ' . __n('minute', 'minutes', $minutes, true) : '';
  611
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d hour', '%d hours', $hours, true), $hours);
  612
+				$relativeDate .= $minutes > 0 ? ($relativeDate ? ', ' : '') . sprintf(__n('%d minute', '%d minutes', $minutes, true), $minutes) : '';
613 613
 			} elseif (abs($minutes) > 0) {
614 614
 				// minutes only
615  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $minutes . ' ' . __n('minute', 'minutes', $minutes, true);
  615
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d minute', '%d minutes', $minutes, true), $minutes);
616 616
 			} else {
617 617
 				// seconds only
618  
-				$relativeDate .= ($relativeDate ? ', ' : '') . $seconds . ' ' . __n('second', 'seconds', $seconds, true);
  618
+				$relativeDate .= ($relativeDate ? ', ' : '') . sprintf(__n('%d second', '%d seconds', $seconds, true), $seconds);
619 619
 			}
620 620
 
621 621
 			if (!$backwards) {
@@ -644,7 +644,7 @@ function relativeTime($dateTime, $options = array()) {
644 644
 /**
645 645
  * Returns true if specified datetime was within the interval specified, else false.
646 646
  *
647  
- * @param mixed $timeInterval the numeric value with space then time type. 
  647
+ * @param mixed $timeInterval the numeric value with space then time type.
648 648
  *    Example of valid types: 6 hours, 2 days, 1 minute.
649 649
  * @param mixed $dateString the datestring or unix timestamp to compare
650 650
  * @param int $userOffset User's offset from GMT (in hours)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.