-
Notifications
You must be signed in to change notification settings - Fork 0
/
count.go
49 lines (41 loc) · 1008 Bytes
/
count.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
package main
import (
"fmt"
"os"
"github.com/simpleapps-eu/translate"
"github.com/simpleapps-eu/translate/dotstrings"
)
func count(fuzzy bool, missing bool, srcName string, tmName string) (err error) {
// Open source file
srcFile, err := os.Open(srcName)
if err != nil {
return
}
defer srcFile.Close()
// Load map of translations from tm file
translations, err := dotstrings.LoadMessagesMapFromFile(tmName)
if err != nil {
return
}
// Start loading the messages asynchronously
msgChan, errChan := dotstrings.LoadMessages(dotstrings.NewReaderUTF16(srcFile))
// Translate messages asynchronously
msgChan = translate.TranslateMessages(msgChan, translations)
// Synchronously receive all messages from the msgChan
var n uint32
for m := range msgChan {
if fuzzy == m.Fuzzy && (missing || !m.Missing) {
n++
}
}
err, _ = <-errChan
if err != nil {
return
}
if fuzzy {
fmt.Printf("%d\tFuzzy strings\n", n)
} else {
fmt.Printf("%d\tNormal strings\n", n)
}
return
}