Browse Source

Merge branch 'unstable' into feature/comments

bastien 13 years ago
parent
commit
3e415809a3

+ 44 - 0
app/Resources/translations/messages.fr.yml View File

@@ -1,3 +1,47 @@
1 1
 
2 2
 Username:     Nom d'utilisateur
3 3
 
4
+date_since:
5
+  default:
6
+    less_min:      Il y a moins d'une minute
7
+    one_min:       Il y a une minute
8
+    one_hour:      Il y a une heure
9
+    one_day:       Il y a un jour
10
+    one_week:       Il y a une semaine
11
+    one_month:       Il y a un mois
12
+    one_year:       Il y a un an
13
+    x_min:         Il y a %x% minutes
14
+    x_hour:        Il y a %x% heures
15
+    x_day:         Il y a %x% jours
16
+    x_week:         Il y a %x% semaines
17
+    x_month:         Il y a %x% mois
18
+    x_year:         Il y a %x% ans
19
+  comment:
20
+    created:
21
+      less_min:      Il y a moins d'une minute
22
+      one_min:       Il y a une minute
23
+      one_hour:      Il y a une heure
24
+      one_day:       Il y a un jour
25
+      one_week:       Il y a une semaine
26
+      one_month:       Il y a un mois
27
+      one_year:       Il y a un an
28
+      x_min:         Il y a %x% minutes
29
+      x_hour:        Il y a %x% heures
30
+      x_day:         Il y a %x% jours
31
+      x_week:         Il y a %x% semaines
32
+      x_month:         Il y a %x% mois
33
+      x_year:         Il y a %x% ans
34
+    edited:
35
+      less_min:      et modifié il y a moins d'une minute
36
+      one_min:       et modifié il y a une minute
37
+      one_hour:      et modifié il y a une heure
38
+      one_day:       et modifié il y a un jour
39
+      one_week:       et modifié il y a une semaine
40
+      one_month:       et modifié il y a un mois
41
+      one_year:       et modifié il y a un an
42
+      x_min:         et modifié il y a %x% minutes
43
+      x_hour:        et modifié il y a %x% heures
44
+      x_day:         et modifié il y a %x% jours
45
+      x_week:         et modifié il y a %x% semaines
46
+      x_month:         et modifié il y a %x% mois
47
+      x_year:         et modifié il y a %x% ans

+ 27 - 32
src/Muzich/CoreBundle/Extension/MyTwigExtension.php View File

@@ -32,8 +32,25 @@ class MyTwigExtension extends \Twig_Extension {
32 32
 
33 33
     return $timestamp;
34 34
   }
35
+  
36
+  protected function translate_date_relative($tr, $type, $x)
37
+  {
38
+    if ($x != 1)
39
+    {
40
+      return $this->translator->trans(
41
+        $tr.'x_'.$type, 
42
+        array('%x%' => $x), 
43
+        'messages'
44
+      );
45
+    }
46
+    return $this->translator->trans(
47
+      $tr.'one_'.$type, 
48
+      array(), 
49
+      'messages'
50
+    );
51
+  }
35 52
 
36
-  public function date_or_relative_date($sentence, $expr = null)
53
+  public function date_or_relative_date($sentence, $context = "default")
37 54
   {
38 55
     $iTimeDifference = time() - $this->datetime2timestamp($sentence);
39 56
     if( $iTimeDifference<0 ) 
@@ -48,57 +65,35 @@ class MyTwigExtension extends \Twig_Extension {
48 65
     $iMonths   	= round( $iTimeDifference/2419200 );
49 66
     $iYears   	= round( $iTimeDifference/29030400 );
50 67
         
68
+    $tr = 'date_since.'.$context.'.';
69
+    
51 70
     if( $iSeconds<60 )
52 71
     {
53
-      return $this->translator->trans('date.less_than_minute', array(), 'userui');
72
+      return $this->translator->trans('date_since.'.$context.'.less_min', array(), 'messages');
54 73
     }
55 74
     elseif( $iMinutes<60 )
56 75
     {
57
-      return $this->translator->transChoice(
58
-        'il y a une minute|Il y a %count% minutes',
59
-        $iMinutes,
60
-        array('%count%' => $iMinutes)
61
-      );
76
+      return $this->translate_date_relative($tr, 'min', $iMinutes);
62 77
     }
63 78
     elseif( $iHours<24 )
64 79
     {
65
-      return $this->translator->transChoice(
66
-        'il y a une heure|Il y a %count% heures',
67
-        $iHours,
68
-        array('%count%' => $iHours)
69
-      );
80
+      return $this->translate_date_relative($tr, 'hour', $iHours);
70 81
     }
71 82
     elseif( $iDays<7 )
72 83
     {
73
-      return $this->translator->transChoice(
74
-        'il y a un jour|Il y a %count% jours',
75
-        $iDays,
76
-        array('%count%' => $iDays)
77
-      );
84
+      return $this->translate_date_relative($tr, 'day', $iDays);
78 85
     }
79 86
     elseif( $iWeeks <4 )
80 87
     {
81
-      return $this->translator->transChoice(
82
-        'il y a une semaine|Il y a %count% semaines',
83
-        $iWeeks,
84
-        array('%count%' => $iWeeks)
85
-      );
88
+      return $this->translate_date_relative($tr, 'week', $iWeeks);
86 89
     }
87 90
     elseif( $iMonths<12 )
88 91
     {
89
-      return $this->translator->transChoice(
90
-        'il y a un mois|Il y a %count% mois',
91
-        $iMonths,
92
-        array('%count%' => $iMonths)
93
-      );
92
+      return $this->translate_date_relative($tr, 'month', $iMonths);
94 93
     }
95 94
     else
96 95
     {
97
-      return $this->translator->transChoice(
98
-        'il y a un an|Il y a %count% ans',
99
-        $iYears,
100
-        array('%count%' => $iYears)
101
-      );
96
+      return $this->translate_date_relative($tr, 'year', $iYears);
102 97
     }
103 98
   }
104 99