Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package timeago |
||
2 | |||
3 | import ( |
||
4 | "fmt" |
||
5 | "path" |
||
6 | "runtime" |
||
7 | ) |
||
8 | |||
9 | type LangForms map[string]string |
||
10 | |||
11 | type LangSet struct { |
||
12 | Lang string `json:"lang"` |
||
13 | Format string `json:"format"` |
||
14 | Ago string `json:"ago"` |
||
15 | Online string `json:"online"` |
||
16 | JustNow string `json:"justnow"` |
||
17 | Second LangForms `json:"second"` |
||
18 | Minute LangForms `json:"minute"` |
||
19 | Hour LangForms `json:"hour"` |
||
20 | Day LangForms `json:"day"` |
||
21 | Week LangForms `json:"week"` |
||
22 | Month LangForms `json:"month"` |
||
23 | Year LangForms `json:"year"` |
||
24 | } |
||
25 | |||
26 | func newLangSet() (*LangSet, error) { |
||
27 | _, filename, _, ok := runtime.Caller(0) |
||
28 | |||
29 | if !ok { |
||
30 | return nil, createError("No called information") |
||
31 | } |
||
32 | |||
33 | rootPath := path.Dir(filename) |
||
34 | filePath := fmt.Sprintf(rootPath+"/langs/%s.json", conf.Language) |
||
35 | |||
36 | if cache, ok := cachedJsonRes[filePath]; ok { |
||
37 | return cache, nil |
||
38 | } |
||
39 | |||
40 | cachedJsonRes[filePath] = parseLangSet(filePath) |
||
41 | |||
42 | return cachedJsonRes[filePath], nil |
||
43 | } |
||
44 |