-
Notifications
You must be signed in to change notification settings - Fork 2
/
DartStringTranslationFlow.go
61 lines (55 loc) · 1.49 KB
/
DartStringTranslationFlow.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 main
import (
"errors"
)
/*
1. Get root string file
2. Get the rest of the string files
3. Clean this up and look for missing keys
4. Reduce if set
5. Generate Dart file
*/
func translateAndroidStringsToDart(config *StringCheeseConfig) error {
// 1. Get root string file
rootStringValue, err := getStringKeys(config.rootLanguageId, config, dartPlatformStringValueProcessor)
if rootStringValue == nil {
return errors.New("Error loading the root string value")
//exit
}
//2. Get the rest of the string files
ids, err := config.getAllValueFoldersLanguageIds()
if err != nil {
return err
//exit
}
stringValues := []*StringKeys{}
for _, id := range ids {
sv, err := getStringKeys(id, config, dartPlatformStringValueProcessor)
if err != nil {
return err
//exit
}
if sv != nil {
stringValues = append(stringValues, sv)
}
}
//3. Clean this up and look for missing keys
//adds missing strings keys to root value
for _, value := range stringValues {
rootStringValue.compareAndAddValues(false, false, value, config)
}
//adds missing string keys to all of the string values from root value
for _, value := range stringValues {
value.compareAndAddValues(true, true, rootStringValue, config)
}
//4. Reduce if set
//reduce keys if option is set
if config.reduceKeys {
rootStringValue.reduceKeys()
for _, value := range stringValues {
value.copyKeys(rootStringValue)
}
}
//5. Generate Dart file
return writeDartFiles(rootStringValue, stringValues, config)
}