-
Notifications
You must be signed in to change notification settings - Fork 0
/
dic.go
61 lines (48 loc) · 1.15 KB
/
dic.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
package bip39
import (
"strings"
"sync"
)
// WordDictionary .
type WordDictionary struct {
WordList []string
ReverseWordMap map[string]int
}
// NewWordDictionary create new bip39 word dictionary
func NewWordDictionary(words string, split string) *WordDictionary {
wordlist := strings.Split(words, split)
reversed := make(map[string]int)
for i, v := range wordlist {
reversed[v] = i
}
return &WordDictionary{
WordList: wordlist,
ReverseWordMap: reversed,
}
}
var mutex sync.RWMutex
// var wordDictionaryZHCN = NewWordDictionary(zhCN, "\n")
var wordDictionaryENUS = NewWordDictionary(enUS, "\n")
var langs = map[string]*WordDictionary{
// "zh_CN": wordDictionaryZHCN,
"en_US": wordDictionaryENUS,
}
// SetDict set language dictionary
func SetDict(lang string, words string, split string) {
mutex.Lock()
defer mutex.Unlock()
langs[lang] = NewWordDictionary(words, split)
}
// GetDict .
func GetDict(lang string) (*WordDictionary, bool) {
dict, ok := langs[lang]
return dict, ok
}
// // ZHCN .
// func ZHCN() *WordDictionary {
// return wordDictionaryZHCN
// }
// ENUS .
func ENUS() *WordDictionary {
return wordDictionaryENUS
}