locale.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package system
  2. // Locale provides language information for the current system.
  3. type Locale struct {
  4. // Language is the BCP-47 tag for the primary language of the system.
  5. Language string
  6. // Direction indicates the primary direction of text and layout
  7. // flow for the system.
  8. Direction TextDirection
  9. }
  10. const (
  11. axisShift = iota
  12. progressionShift
  13. )
  14. // TextDirection defines a direction for text flow.
  15. type TextDirection byte
  16. const (
  17. // LTR is left-to-right text.
  18. LTR TextDirection = TextDirection(Horizontal<<axisShift) | TextDirection(FromOrigin<<progressionShift)
  19. // RTL is right-to-left text.
  20. RTL TextDirection = TextDirection(Horizontal<<axisShift) | TextDirection(TowardOrigin<<progressionShift)
  21. )
  22. // Axis returns the axis of the text layout.
  23. func (d TextDirection) Axis() TextAxis {
  24. return TextAxis((d & (1 << axisShift)) >> axisShift)
  25. }
  26. // Progression returns the way that the text flows relative to the origin.
  27. func (d TextDirection) Progression() TextProgression {
  28. return TextProgression((d & (1 << progressionShift)) >> progressionShift)
  29. }
  30. func (d TextDirection) String() string {
  31. switch d {
  32. case RTL:
  33. return "RTL"
  34. default:
  35. return "LTR"
  36. }
  37. }
  38. // TextAxis defines the layout axis of text.
  39. type TextAxis byte
  40. const (
  41. // Horizontal indicates text that flows along the X axis.
  42. Horizontal TextAxis = iota
  43. // Vertical indicates text that flows along the Y axis.
  44. Vertical
  45. )
  46. // TextProgression indicates how text flows along an axis relative to the
  47. // origin. For these purposes, the origin is defined as the upper-left
  48. // corner of coordinate space.
  49. type TextProgression byte
  50. const (
  51. // FromOrigin indicates text that flows along its axis away from the
  52. // origin (upper left corner).
  53. FromOrigin TextProgression = iota
  54. // TowardOrigin indicates text that flows along its axis towards the
  55. // origin (upper left corner).
  56. TowardOrigin
  57. )