-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIOSStringTranslationFlow.go
More file actions
71 lines (66 loc) · 1.8 KB
/
IOSStringTranslationFlow.go
File metadata and controls
71 lines (66 loc) · 1.8 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
package main
/*
1. Get root string file
2. Get the rest of the string files
3. Clean this up and look for missing keys
4. Generate Swift file if needed
5. Reduce keys if need, but only if a Swift file is needed
6. Generate .strings files
*/
func translateAndroidStringsToIOS(config *StringCheeseConfig) error {
// 1. Get root string file
rootStringValue, err := getStringKeys(config.rootLanguageId, config, iOSPlatformStringValueProcessor)
if err != nil {
return err
//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, iOSPlatformStringValueProcessor)
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. Generate Swift file if needed
if config.shouldCreateSwiftKey {
// 5. Reduce keys if need, but only if a Swift file is needed
if config.reduceKeys {
rootStringValue.reduceKeys()
for _, value := range stringValues {
value.copyKeys(rootStringValue)
}
}
writeSwiftKeyFile(rootStringValue, config)
}
// 6. Generate .strings files
err = writeStringValueToDotStrings(rootStringValue, config)
if err != nil {
return err
}
for _, value := range stringValues {
err = writeStringValueToDotStrings(value, config)
if err != nil {
return err
}
}
return nil
}