1
|
|
|
package timeago |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"fmt" |
5
|
|
|
) |
6
|
|
|
|
7
|
|
|
// getTimeTranslations returns array of translations for different |
8
|
|
|
// cases. For example `1 second` must not have `s` at the end |
9
|
|
|
// but `2 seconds` requires `s`. So this method keeps all |
10
|
|
|
// possible options for the translated word. |
11
|
|
|
func getTimeTranslations() map[string]map[string]string { |
12
|
1 |
|
return map[string]map[string]string{ |
13
|
|
|
"seconds": { |
14
|
|
|
"single": trans().Second, |
15
|
|
|
"plural": trans().Seconds, |
16
|
|
|
"special": trans().SecondsSpecial, |
17
|
|
|
}, |
18
|
|
|
"minutes": { |
19
|
|
|
"single": trans().Minute, |
20
|
|
|
"plural": trans().Minutes, |
21
|
|
|
"special": trans().MinutesSpecial, |
22
|
|
|
}, |
23
|
|
|
"hours": { |
24
|
|
|
"single": trans().Hour, |
25
|
|
|
"plural": trans().Hours, |
26
|
|
|
"special": trans().HoursSpecial, |
27
|
|
|
}, |
28
|
|
|
"days": { |
29
|
|
|
"single": trans().Day, |
30
|
|
|
"plural": trans().Days, |
31
|
|
|
"special": trans().DaysSpecial, |
32
|
|
|
}, |
33
|
|
|
"weeks": { |
34
|
|
|
"single": trans().Week, |
35
|
|
|
"plural": trans().Weeks, |
36
|
|
|
"special": trans().WeeksSpecial, |
37
|
|
|
}, |
38
|
|
|
"months": { |
39
|
|
|
"single": trans().Month, |
40
|
|
|
"plural": trans().Months, |
41
|
|
|
"special": trans().MonthsSpecial, |
42
|
|
|
}, |
43
|
|
|
"years": { |
44
|
|
|
"single": trans().Year, |
45
|
|
|
"plural": trans().Years, |
46
|
|
|
"special": trans().YearsSpecial, |
47
|
|
|
}, |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
func getLanguageForm(num int) string { |
52
|
1 |
|
var form string |
53
|
1 |
|
lastDigit := getLastNumber(num) |
54
|
1 |
|
rule := getRules(num, lastDigit)[language] |
55
|
|
|
|
56
|
1 |
|
switch { |
57
|
|
|
case rule.Special: |
58
|
1 |
|
return "special" |
59
|
|
|
case rule.Single: |
60
|
1 |
|
return "single" |
61
|
|
|
case rule.Plural: |
62
|
1 |
|
return "plural" |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
fmt.Printf("Provided rules don't apply to a number %d", num) |
66
|
|
|
|
67
|
|
|
return form |
68
|
|
|
} |
69
|
|
|
|