This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
translations.go
62 lines (53 loc) · 1.66 KB
/
translations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package trans
import (
"github.com/go-playground/locales"
"github.com/go-playground/log"
"github.com/go-playground/universal-translator"
)
// Add add normal translation and wraps error
func Add(trans ut.Translator, key interface{}, text string, override bool) {
err := trans.Add(key, text, override)
if err != nil {
log.StackTrace().WithFields(
log.F("key", key),
log.F("text", text),
log.F("error", err),
).Fatal("issue adding translation")
}
}
// AddRange adds a range translation and wraps error
func AddRange(trans ut.Translator, key interface{}, text string, rule locales.PluralRule, override bool) {
err := trans.AddRange(key, text, rule, override)
if err != nil {
log.StackTrace().WithFields(
log.F("key", key),
log.F("text", text),
log.F("rule", rule),
log.F("error", err),
).Fatal("issue adding range translation")
}
}
// AddCardinal adds a cardinal translation and wraps error
func AddCardinal(trans ut.Translator, key interface{}, text string, rule locales.PluralRule, override bool) {
err := trans.AddCardinal(key, text, rule, override)
if err != nil {
log.StackTrace().WithFields(
log.F("key", key),
log.F("text", text),
log.F("rule", rule),
log.F("error", err),
).Fatal("issue adding cardinal translation")
}
}
// AddOrdinal adds an ordinal translation and wraps error
func AddOrdinal(trans ut.Translator, key interface{}, text string, rule locales.PluralRule, override bool) {
err := trans.AddOrdinal(key, text, rule, override)
if err != nil {
log.StackTrace().WithFields(
log.F("key", key),
log.F("text", text),
log.F("rule", rule),
log.F("error", err),
).Fatal("issue adding ordinal translation")
}
}