forked from jeandeaual/go-locale
-
Notifications
You must be signed in to change notification settings - Fork 1
/
locale_ios.go
52 lines (41 loc) · 1.06 KB
/
locale_ios.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
//go:build ios
// +build ios
package locale
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework UIKit
const char *getLocale();
const char *getLocales();
*/
import "C"
import (
"strings"
)
// GetLocale retrieves the IETF BCP 47 language tag set on the system.
func GetLocale() (string, error) {
return C.GoString(C.getLocale()), nil
}
// GetLocales retrieves the IETF BCP 47 language tags set on the system.
func GetLocales() ([]string, error) {
return strings.Split(C.GoString(C.getLocales()), ","), nil
}
// GetLanguage retrieves the IETF BCP 47 language tag set on the system and
// returns the language part of the tag.
func GetLanguage() (string, error) {
language := ""
locale, err := GetLocale()
if err == nil {
language, _ = splitLocale(locale)
}
return language, err
}
// GetRegion retrieves the IETF BCP 47 language tag set on the system and
// returns the region part of the tag.
func GetRegion() (string, error) {
region := ""
locale, err := GetLocale()
if err == nil {
_, region = splitLocale(locale)
}
return region, err
}