-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
lockdown_language_locale.go
59 lines (53 loc) · 2.14 KB
/
lockdown_language_locale.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
package ios
import log "github.com/sirupsen/logrus"
//LanguageConfiguration is a simple struct encapsulating a language and locale string
type LanguageConfiguration struct {
Language string
Locale string
}
const languageDomain = "com.apple.international"
//SetLanguage creates a new lockdown session for the device and sets a new language and locale.
//Changes will only be made when the value is not an empty string. To change only the locale, set language to ""
//and vice versa. If both are empty, nothing is changed.
//NOTE: Changing a language is an async operation that takes a long time. Springboard will be restarted automatically by the device.
//If you need to wait for this happen use notificationproxy.WaitUntilSpringboardStarted().
func SetLanguage(device DeviceEntry, config LanguageConfiguration) error {
if config.Locale == "" && config.Language == "" {
log.Debug("SetLanguage called with empty config, no changes made")
return nil
}
lockDownConn, err := ConnectLockdownWithSession(device)
if err != nil {
return err
}
defer lockDownConn.Close()
if config.Locale != "" {
log.Debugf("Setting locale: %s", config.Locale)
err := lockDownConn.SetValueForDomain("Locale", languageDomain, config.Locale)
if err != nil {
return err
}
}
if config.Language != "" {
log.Debugf("Setting language: %s", config.Locale)
return lockDownConn.SetValueForDomain("Language", languageDomain, config.Language)
}
return nil
}
//GetLanguage creates a new lockdown session for the device and retrieves language and locale. It returns a LanguageConfiguration or an error.
func GetLanguage(device DeviceEntry) (LanguageConfiguration, error) {
lockDownConn, err := ConnectLockdownWithSession(device)
if err != nil {
return LanguageConfiguration{}, err
}
defer lockDownConn.Close()
languageResp, err := lockDownConn.GetValueForDomain("Language", languageDomain)
if err != nil {
return LanguageConfiguration{}, err
}
localeResp, err := lockDownConn.GetValueForDomain("Locale", languageDomain)
if err != nil {
return LanguageConfiguration{}, err
}
return LanguageConfiguration{Language: languageResp.(string), Locale: localeResp.(string)}, nil
}