summaryrefslogtreecommitdiffstats
path: root/src/dia_lang.inc
blob: 121f67223ecc082addfd669c3caa17d54f4f9b07 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%
% Language selection dialog.
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Some global vars.
%

% fallback if there is no "langs"
/lang.items [ "en_US" ] def
/lang.names [ "English (US)" ] def

/.la.locale 0 def
/.la.keymap 1 def
/.la.rtl    2 def
/.la.name   3 def

/lang.defaultnames [
  [ "af_ZA" "en_US" false "Afrikaans" ]						% Afrikaans
% [ "ar_EG" "en_US" true  "\u064a\u0628\u0631\u0639" ]				% Arabic
  [ "ar_EG" "en_US" true  "\ufef2\ufe91\ufeae\ufecb" ]				% Arabic
  [ "bg_BG" "en_US" false "Български" ]						% Bulgarian
  [ "bn_BD" "en_US" false "\u09ac\u09be\u0982\u09b2\u09be" ]			% Bengali
  [ "bs_BA" "en_US" false "Bosanski" ]						% Bosnian
  [ "ca_ES" "en_US" false "Català" ]						% Catalan
  [ "cs_CZ" "czech" false "Čeština" ]						% Czech
  [ "cy_GB" "en_US" false "Cymraeg" ]						% Welsh
  [ "da_DK" "danish" false "Dansk" ]						% Danish
  [ "de_DE" "german" false "Deutsch" ]						% German
  [ "el_GR" "greek" false "Ελληνικά" ]						% Greek
  [ "en_GB" "en_US" false "English (UK)" ]					% English
  [ "en_US" "en_US" false "English (US)" ]					% English
  [ "es_ES" "spanish" false "Español" ]						% Spanish
  [ "et_EE" "estonian" false "Eesti" ]						% Estonian
  [ "fa_IR" "en_US" true "\ufbfd\ufeb4\u0631\ufe8e\ufed3" ]			% Farsi
  [ "fi_FI" "en_US" false "Suomi" ]						% Finnish
  [ "fr_FR" "french" false "Français" ]						% French
  [ "gl_ES" "en_US" false "Galego" ]						% Galician
  [ "ka_GE" "en_US" false "ქართული" ]						% Kartuli
  [ "gu_IN" "en_US" false "\u0a97\u0ac1\u0a9c\u0ab0\u0abe\u0aa4\u0ac0" ]	% Gujarati
  [ "he_IL" "en_US" false "תירבע" ]						% Hebrew
% [ "hi_IN" "en_US" false "\u0939\u093f\u0928\u094d\u0926\u0940" ]		% Hindi
  [ "hi_IN" "en_US" false "\u0939\u093f\u0902\u0926\u0940" ]			% Hindi
  [ "hr_HR" "en_US" false "Hrvatski" ]						% Croatian
  [ "hu_HU" "hungarian" false "Magyar" ]						% Hungarian
  [ "id_ID" "en_US" false "Bahasa Indonesia" ]					% Indonesian
  [ "it_IT" "italian" false "Italiano" ]						% Italian
  [ "ja_JP" "japanese" false "日本語" ]						% Japanese
  [ "jv_ID" "en_US" false "Basa Jawa" ]						% Javanese
% [ "km_KH" "en_US" false "\u1781\u17d2\u1798\u17c2\u179a" ]			% Khmer
  [ "km_KH" "en_US" false "Khmer" ]						% Khmer
  [ "ko_KR" "en_US" false "한글" ]						% Korean
  [ "ky_KG" "en_US" false "Кыргызча" ]						% Kirghiz
  [ "lo_LA" "en_US" false "\u0e9e\u0eb2\u0eaa\u0eb2\u0ea5\u0eb2\u0ea7" ]	% Lao
  [ "lt_LT" "en_US" false "Lietuvių" ]						% Lithuanian
  [ "mk_MK" "en_US" false "Македонски" ]					% Macedonian
  [ "mr_IN" "en_US" false "\u092e\u0930\u093e\u0920\u0940" ]			% Marathi
  [ "nb_NO" "norwegian" false "Norsk (bokmål)" ]				% Norwegian
  [ "nn_NO" "norwegian" false "Norsk (nynorsk)" ]				% Norwegian
  [ "nl_NL" "en_US" false "Nederlands" ]					% Dutch
  [ "pa_IN" "en_US" false "\u0a2a\u0a70\u0a1c\u0a3e\u0a2c\u0a40" ]		% Punjabi
  [ "pl_PL" "polish" false "Polski" ]						% Polish
  [ "pt_PT" "portugese" false "Português" ]					% Portuguese
  [ "pt_BR" "portugese-br" false "Português (Brasil)" ]				% Portuguese (Brazilian)
  [ "ro_RO" "en_US" false "Română" ]						% Romanian
  [ "ru_RU" "russian" false "Русский" ]						% Russian
  [ "si_LK" "en_US" false "\u0dc3\u0dd2\u0d82\u0dc4\u0dbd" ]			% Sinhala
  [ "sk_SK" "slovak" false "Slovenčina" ]					% Slovak
  [ "sl_SI" "slovene" false "Slovenščina" ]					% Slovenian
  [ "sr_CS" "en_US" false "Srpski" ]						% Serbian
  [ "sv_SE" "swedish" false "Svenska" ]						% Swedish
  [ "ta_IN" "en_US" false "\u0ba4\u0bae\u0bbf\u0bb4\u0bcd" ]			% Tamil
  [ "th_TH" "en_US" false "\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22" ] 	% Thai
  [ "tr_TR" "turkish" false "Türkçe" ]						% Turkish
  [ "uk_UA" "en_US" false "Українська" ]					% Ukrainian
  [ "vi_VN" "en_US" false "Tiếng Việt" ]					% Vietnamese
  [ "wa_BE" "en_US" false "Walon" ]						% Walloon
  [ "xh_ZA" "en_US" false "isiXhosa" ]						% Xhosa
  [ "zh_CN" "en_US" false "简体中文" ]						% Simplified Chinese
  [ "zh_TW" "en_US" false "繁體中文 (台灣)" ]					% Traditional Chinese
  [ "zu_ZA" "en_US" false "isiZulu" ]						% Zulu
] def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Get language property.
%
% Returns .undef if not found.
%
% ( locale prop ) ==> ( obj )
%
/lang.getprop {
  lang.defaultnames {
    dup .la.locale get 3 index eq { exch get exch pop return } { pop } ifelse
  } forall

  % try a loose match
  lang.defaultnames {
    dup .la.locale get 3 index locale.cmp { exch get exch pop return } { pop } ifelse
  } forall

  pop pop .undef
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Get language name.
%
% Returns locale if not found.
%
% ( locale ) ==> ( name )
%
/lang.getdefname {
  dup
  .la.name lang.getprop
  dup .undef ne { exch } if
  pop
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Check for rtl.
%
% ( locale ) ==> ( bool )
%
/lang.getrtl {
  .la.rtl lang.getprop
  dup .undef eq { pop false } if
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Parse "langs" file.
%
% ( ) ==> ( )
%
/lang.parsedata {
  /lang.default 0 def

  "langs" findfile dup { /lang.data exch def } { pop return } ifelse

  /la.tmp.datalen lang.data length def
  /la.tmp.str lang.data cvs def
 
  la.tmp.datalen 0 eq { return } if
  la.tmp.str la.tmp.datalen 1 sub get '\n' ne { return } if

  '\n' seteotchar

  /lang.items [

    /la.tmp.len 0 def
    /la.tmp.cnt 0 def
    {
      la.tmp.str la.tmp.len add strdup
      dup dup length 0 put
      /la.tmp.len over length 1 add la.tmp.len add def

      dup 0 get '*' eq { 1 add /lang.default la.tmp.cnt def } if

      la.tmp.len la.tmp.datalen ge { exit } if

      /la.tmp.cnt inc
    } loop

  ] def

  ' ' seteotchar

  /lang.names [

    lang.items {

      dup dup length add

      dup 0 get {
        dup 0 0 put 1 add
        exch pop
      } {
        pop lang.getdefname
      } ifelse

    } forall

    keymap.submenu {
      /lang.submenu.keyboard
    } if

  ] def

  /lang.submenu.idx keymap.submenu { lang.names length 1 sub } { -1 } ifelse def

  0 seteotchar

} def


/lang.submenu.keyboard.buf 64 string def
/lang.submenu.keyboard {
  /txt_keyboard exec "\x09%s" lang.submenu.keyboard.buf sprintf
  lang.submenu.keyboard.buf
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Build language list.
%
% ( ) ==> ( )
%
/lang.init {
  /xmenu.lang .xm_size array def
  /xmenu xmenu.lang def

  lang.parsedata

  xmenu .xm_current lang.default put
  xmenu .xm_list lang.names put

  xmenu .xm_title /txt_language put

  % make menu smaller if there are more than 19 language entries
  %lang.items length 19 gt {
  %  xmenu .xm_vspace 2 put
  %} if

  % start with current lang

  /la.tmp.cnt 0 def
  lang.items {
    config.lang locale.cmp { xmenu .xm_current la.tmp.cnt put exit } if
    /la.tmp.cnt inc
  } forall

  /la.tmp.cnt 0 def
  lang.items {
    config.lang eq { xmenu .xm_current la.tmp.cnt put exit } if
    /la.tmp.cnt inc
  } forall

  % needed in case menu is only attached to lang menu
  keymap.init
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Update language.
%
% ( ) ==> ( )
%
/lang.update {
  /xmenu xmenu.lang def

  xmenu .xm_current get lang.submenu.idx eq {
    xmenu .xm_current over .xm_last get put
    panel.keymap
  } {
    lang.items xmenu .xm_current get get
    dup
    setlang { /window.action actRedraw def } if
    getkeymapfromlocale setkeymap
    keymap.setdefault
  } ifelse

} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Show language menu.
%
% ( ) => ( )
%
/panel.lang {
  "keytable" help.setcontext

  window.xmenu
  dup .xmenu xmenu.lang put
  dup .xmenu.update /lang.update put
  dup window.init
      window.show
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Return width of panel entry.
%
% ( ) => ( width )
%
/panel.lang.width {
  /xmenu xmenu.lang def

  pmenu.width
} def


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Redraw panel entry.
%
% ( panel ) => ( )
%
/panel.lang.update {
  /xmenu xmenu.lang def

  pmenu.panel.update

  xmenu.keymap .xm_panel_x xmenu.lang .xm_panel_x get put
} def