summaryrefslogtreecommitdiff
path: root/.zsh/zprofile/10_locale
blob: e2902bb64858fb680ab065b617ede3efdaf46386 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# zprofile/10_locale
#
# Define locale settings
#
# Copyright © 1994–2008 martin f. krafft <madduck@madduck.net>
# Copyright © 2011 Tobias Klauser <tklauser@distanz.ch>
# Released under the terms of the Artistic Licence 2.0
#
# Source repository: git://git.distanz.ch/dotfiles/zsh.git

_set_locale()
{
  export LC_CTYPE=$1
  export LC_COLLATE=$1
  export LC_MESSAGES=$1
  export LC_TIME=$1
  _set_regional_locale $1
}

_set_regional_locale()
{
  export LC_NUMERIC=$1
  export LC_MONETARY=$1
  export LC_PAPER=$1
  export LC_NAME=$1
  export LC_ADDRESS=$1
  export LC_TELEPHONE=$1
  export LC_MEASUREMENT=$1
  export LC_IDENTIFICATION=$1
}

if [ -x =locale ]; then
  _LOCALE="$(locale -a)"

  # Prefer British English and UTF-8 over US English and non-UTF-8
  case "$_LOCALE" in
    *en_GB.utf8*)
      _set_locale en_GB.UTF-8
      export LANG=en_GB
      ;;
    # named differently on Mac OS X
    *en_GB.UTF-8*)
      _set_locale en_GB.UTF-8
      export LANG=en_GB
      ;;
    *en_US.utf8*)
      _set_locale en_US.UTF-8
      export LANG=en_US
      ;;
    # named differently on Mac OS X
    *en_US.UTF-8*)
      _set_locale en_US.UTF-8
      export LANG=en_US
      ;;
    *en_GB.iso885915*)
      _set_locale en_GB.ISO-8859-15
      warn "no utf-8 locale available"
      export LANG=en_GB
      ;;
    *en_US.iso885915*)
      warn "no utf-8 locale available"
      _set_locale en_US.ISO-8859-15
      export LANG=en_US
      ;;
    *en_GB.iso88591*)
      warn "no utf-8 locale available"
      _set_locale en_GB.ISO-8859-1
      export LANG=en_GB
      ;;
    *en_US.iso88591*)
      warn "no utf-8 locale available"
      _set_locale en_US.ISO-8859-1
      export LANG=en_US
      ;;
    *en_GB*)
      warn "no utf-8 or iso locale available"
      _set_locale en_GB
      export LANG=en_GB
      ;;
    *en_US*)
      warn "no utf-8 or iso locale available"
      _set_locale en_US
      export LANG=en_US
      ;;
  esac

  # regional stuff should be Swiss over German
  case "$_LOCALE" in
    *de_CH.utf8*)
      _set_regional_locale de_CH.UTF-8
      ;;
    # named differently on Mac OS X
    *de_CH.UTF-8*)
      _set_regional_locale de_CH.UTF-8
      ;;
    *de_CH.iso885915*)
      _set_regional_locale de_CH.ISO-8859-15
      ;;
    *de_CH.iso88591*)
      _set_regional_locale de_CH.ISO-8859-1
      ;;
    *de_DE.utf8*)
      _set_regional_locale de_DE.UTF-8
      ;;
    *de_DE.iso885915*)
      _set_regional_locale de_DE.ISO-8859-15
      ;;
    *de_DE.iso88591*)
      _set_regional_locale de_DE.ISO-8859-1
      ;;
  esac
  unset _LOCALE
fi

export LANGUAGE="${LANG}:en"

unfunction _set_regional_locale
unfunction _set_locale

# vim:ft=zsh