-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdevice.go
37 lines (30 loc) · 1 KB
/
device.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
package localization
import (
"context"
"strings"
"github.com/code-payments/code-server/pkg/grpc/client"
)
// GetLocalizationKeyForUserAgent gets a localization key in the format for the device
// as provided in the user agent header. If an unknown device type, or the user- gent
// header isn't available, then the original key is returned.
func GetLocalizationKeyForUserAgent(ctx context.Context, key string) string {
userAgent, err := client.GetUserAgent(ctx)
if err != nil {
return key
}
switch userAgent.DeviceType {
case client.DeviceTypeIOS:
return GetIosLocalizationKey(key)
case client.DeviceTypeAndroid:
return GetAndroidLocalizationKey(key)
}
return key
}
// GetIosLocalizationKey gets a localization string in the iOS format
func GetIosLocalizationKey(key string) string {
return strings.Replace(key, "_", ".", -1)
}
// GetAndroidLocalizationKey gets a localization string in the Android format
func GetAndroidLocalizationKey(key string) string {
return strings.Replace(key, ".", "_", -1)
}