-
Notifications
You must be signed in to change notification settings - Fork 8
/
tr.go
38 lines (30 loc) · 798 Bytes
/
tr.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
package tr
// DefaultEngine is what used when calling package-scope Tr().
var DefaultEngine *Engine
func init() {
DefaultEngine = &Engine{}
}
// Pass TrimEnd as an optional 3rd argument to trim \n ending.
const TrimEnd = true
// Init is used to set the locales directory, as well as the
// default locale.
func Init(path, defaultLocale string, trimOptional ...bool) error {
trim := false
if len(trimOptional) > 0 {
trim = true
}
engine, err := NewEngine(path, defaultLocale, trim)
if err != nil {
return err
}
DefaultEngine = engine
return nil
}
// Tr provides default locale's translation of path.
func Tr(path string) string {
return DefaultEngine.Tr(path)
}
// Lang returns a *Locale by name.
func Lang(localeName string) *Locale {
return DefaultEngine.Lang(localeName)
}