You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-14Lines changed: 25 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,20 @@
16
16
2 yrs <-> max time or date # => over [2..X] years
17
17
```
18
18
19
-
This is the default `RuleSet` TimeAgo works with, but it could be changed depending on your needs:
19
+
Above example is using the default `RuleSet`, but you can define your own when you want:
20
20
21
21
```
22
22
$ruleSet = new Technodelight\TimeAgo\Translation\RuleSet;
23
-
$ruleSet->add(new Rule('aboutOneDay', '23hour'), new Formatter('days', 'day'));
23
+
$ruleSet->add(
24
+
new Rule(
25
+
'aboutOneDay', // rule name, which would be used as a translation key
26
+
'23hour' // timespan, as a limit, without spaces between numerics and time. Check DefaultRuleSet for examples
27
+
),
28
+
new Formatter(
29
+
'days', // duration type, according to durations in \Technodelight\TimeAgo\Translation\SecondsDurationMap
30
+
'floor' // strategy (function) to use for calculating the amount. In this example "days" are calculated with floor()
31
+
)
32
+
);
24
33
$timeAgo = new Technodelight\TimeAgo(
25
34
new DateTime('-1 hour'),
26
35
new Technodelight\TimeAgo\Translator(
@@ -32,32 +41,34 @@ $timeAgo = new Technodelight\TimeAgo(
32
41
$timeAgo->inWords(); // => 1 day ago
33
42
```
34
43
35
-
With the above code you can pass any of the translations supplied with this repository. All credits goes to Jimmi Westerberg and the contributors, who added this
36
-
awesomeness factor.
44
+
The example below shows how customisable is TimeAgo:
37
45
38
46
```
39
-
$translationLoader = new Technodelight\TimeAgo\TranslationLoader;
47
+
// with all dependencies injected:
48
+
$translationLoader = new Technodelight\TimeAgo\TranslationLoader; // can load built-in translations
40
49
$timeAgo = new Technodelight\TimeAgo(
41
-
new DateTime('-1 hour'),
42
-
new Technodelight\TimeAgo\Translator(
43
-
$translationLoader->load('hu')
50
+
new DateTime('-1 hour'), // static datetime
51
+
new Technodelight\TimeAgo\Translator( // this only needs an array as an input
52
+
$translationLoader->load('hu') // use a fixed translation
In the above example you can pass any of the translations supplied with this repository. All credits goes to Jimmi Westerberg and to the contributors of his repository.
63
+
51
64
By default, the `TimeAgo` uses the current system language as a guide to determine the required translation file, and it defaults to english if this information was not successfully resolved.
52
-
Of course, you can configure the translation loader to define your own translation directory and use the translations from there:
65
+
Of course, you can pass your own translation when required:
53
66
54
67
```
55
-
$translationLoader = new Technodelight\TimeAgo\TranslationLoader;
0 commit comments