-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStringValue.go
More file actions
128 lines (113 loc) · 2.93 KB
/
StringValue.go
File metadata and controls
128 lines (113 loc) · 2.93 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"fmt"
"sort"
"strconv"
)
/*
The StringValue struct is a single translated string
It contains the original key and the reduced key if needed
The value is the translated string value
*/
type StringValue struct {
translatable bool
originalKey string
key string
value string
numberOfArguments int
argumentString string
formatString string
}
/*
StringKeys are a pairing between StringValues and a language
*/
type StringKeys struct {
languageId string
strings map[string]*StringValue //map of key to StringValue, StringValue's contain their own key mapping in StringValue.key
}
/*
Compares strings against another StringKeys struct,
It adds a blank StringValue for every missing key
If logMissingStrings is true, it logs this to console
*/
func (sk *StringKeys) compareAndAddValues(skipUntranslatableStrings bool, fillInBlankFromOther bool, other *StringKeys, config *StringCheeseConfig) {
for otherKey, otherValue := range other.strings {
if skipUntranslatableStrings && otherValue.translatable == false {
continue
}
var found = false
for mainKey, mainValue := range sk.strings {
if mainKey == otherKey {
if fillInBlankFromOther && len(mainValue.value) == 0 {
break
}
found = true
break
}
}
if found == false {
v := StringValue{}
v = *otherValue
if fillInBlankFromOther {
v.value = otherValue.value
} else {
v.value = ""
}
sk.strings[otherKey] = &v
if config.logMissingStrings {
fmt.Println(sk.languageId + " String Key file is missing string with id - " + v.originalKey)
}
}
}
}
/*
Reduce keys by just turning them into an int
eventually you could reduce the keys even further by using a-z A-Z 0-9, but I don't see the point
*/
func (sk *StringKeys) reduceKeys() {
var oldKeys = sk.strings
sk.strings = map[string]*StringValue{}
var index = 0
for _, value := range oldKeys {
newKey := strconv.Itoa(index)
value.key = newKey
sk.strings[newKey] = value
index++
}
}
/*
Reduce keys by just turning them into an int
eventually you could reduce the keys even further by using a-z A-Z 0-9, but I don't see the point
*/
func (sk *StringKeys) getSortedValues() []*StringValue {
values := []*StringValue{}
for _, value := range sk.strings {
values = append(values, value)
}
sort.Slice(values, func(i, j int) bool { return values[i].key < values[j].key })
return values
}
/*
Copies keys based off the original key value.
skipped non-translated strings
*/
func (sk *StringKeys) copyKeys(other *StringKeys) {
for key, value := range other.strings {
if value.translatable == false {
continue
}
var found = false
for myKey, myValue := range sk.strings {
if myKey == value.originalKey {
myValue.key = key
sk.strings[key] = myValue
delete(sk.strings, myKey)
found = true
break
}
}
if found == false {
fmt.Println("BUG in key reducing could not find matching key " + value.originalKey)
}
}
}