locale.go 549 B

12345678910111213141516171819202122232425
  1. package fyne
  2. import "strings"
  3. // Locale represents a user's locale (language, region and script)
  4. //
  5. // Since: 2.5
  6. type Locale string
  7. // LanguageString returns a version of the local without the script portion.
  8. // For example "en" or "fr-FR".
  9. func (l Locale) LanguageString() string {
  10. count := strings.Count(string(l), "-")
  11. if count < 2 {
  12. return string(l)
  13. }
  14. pos := strings.LastIndex(string(l), "-")
  15. return string(l)[:pos]
  16. }
  17. // String returns the complete locale as a standard string.
  18. func (l Locale) String() string {
  19. return string(l)
  20. }