-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
43 lines (33 loc) · 961 Bytes
/
utils.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
package locale
import (
"math"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
func checkIfInitializaed() {
if fallbackLanguage == language.Und {
panic("locale is not initialized. Did you forget to run Initialize()?")
}
}
func getLocalizer(tag language.Tag) *i18n.Localizer {
checkIfInitializaed()
localizer := localizers[tag]
// If localizer was not found, fallback
// to the one for the default language
if localizer == nil {
return localizers[fallbackLanguage]
}
return localizer
}
// Convert an array of strings to a map of strings.
// Omit last element if the number of elements is odd.
//
// For example, when the input is ["a", "b", "c"]
// this function will return the following map: {"a": "b"}
func parseArgs(args []any) map[string]any {
var argMap = make(map[string]any, 0)
for i := 0; i < 2*int(math.Floor(float64(len(args))/2)); i += 2 {
argMap[args[i].(string)] = args[i+1]
}
return argMap
}