Browse Source

Amélioration translation de date since.

bastien 13 years ago
parent
commit
c42ca1be37

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

@@ -1,2 +1,47 @@
1 1
 
2 2
 Username:     Nom d'utilisateur
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

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