7
|
1 " Vim tutor support file
|
|
2 " Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es>
|
1698
|
3 " Maintainer: Bram Moolenaar
|
6009
|
4 " Last Change: 2014 Jun 25
|
7
|
5
|
1698
|
6 " This Vim script is used for detecting if a translation of the
|
7
|
7 " tutor file exist, i.e., a tutor.xx file, where xx is the language.
|
|
8 " If the translation does not exist, or no extension is given,
|
|
9 " it defaults to the english version.
|
|
10
|
|
11 " It is invoked by the vimtutor shell script.
|
|
12
|
|
13 " 1. Build the extension of the file, if any:
|
|
14 let s:ext = ""
|
|
15 if strlen($xx) > 1
|
|
16 let s:ext = "." . $xx
|
|
17 else
|
|
18 let s:lang = ""
|
782
|
19 " Check that a potential value has at least two letters.
|
|
20 " Ignore "1043" and "C".
|
|
21 if exists("v:lang") && v:lang =~ '\a\a'
|
7
|
22 let s:lang = v:lang
|
782
|
23 elseif $LC_ALL =~ '\a\a'
|
205
|
24 let s:lang = $LC_ALL
|
782
|
25 elseif $LANG =~ '\a\a'
|
7
|
26 let s:lang = $LANG
|
|
27 endif
|
|
28 if s:lang != ""
|
|
29 " Remove "@euro" (ignoring case), it may be at the end
|
|
30 let s:lang = substitute(s:lang, '\c@euro', '', '')
|
|
31 " On MS-Windows it may be German_Germany.1252 or Polish_Poland.1250. How
|
|
32 " about other languages?
|
|
33 if s:lang =~ "German"
|
|
34 let s:ext = ".de"
|
|
35 elseif s:lang =~ "Polish"
|
|
36 let s:ext = ".pl"
|
|
37 elseif s:lang =~ "Slovak"
|
|
38 let s:ext = ".sk"
|
6009
|
39 elseif s:lang =~ "Serbian"
|
|
40 let s:ext = ".sr"
|
1154
|
41 elseif s:lang =~ "Czech"
|
|
42 let s:ext = ".cs"
|
782
|
43 elseif s:lang =~ "Dutch"
|
|
44 let s:ext = ".nl"
|
7
|
45 else
|
|
46 let s:ext = "." . strpart(s:lang, 0, 2)
|
|
47 endif
|
|
48 endif
|
|
49 endif
|
|
50
|
1621
|
51 " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
|
|
52 if s:ext =~? '\.ge'
|
|
53 let s:ext = ".de"
|
|
54 endif
|
|
55
|
|
56 if s:ext =~? '\.en'
|
|
57 let s:ext = ""
|
|
58 endif
|
|
59
|
7
|
60 " The japanese tutor is available in two encodings, guess which one to use
|
|
61 " The "sjis" one is actually "cp932", it doesn't matter for this text.
|
|
62 if s:ext =~? '\.ja'
|
|
63 if &enc =~ "euc"
|
|
64 let s:ext = ".ja.euc"
|
1621
|
65 elseif &enc != "utf-8"
|
7
|
66 let s:ext = ".ja.sjis"
|
|
67 endif
|
|
68 endif
|
|
69
|
|
70 " The korean tutor is available in two encodings, guess which one to use
|
|
71 if s:ext =~? '\.ko'
|
1621
|
72 if &enc != "utf-8"
|
7
|
73 let s:ext = ".ko.euc"
|
|
74 endif
|
|
75 endif
|
|
76
|
3830
|
77 " The Chinese tutor is available in three encodings, guess which one to use
|
7
|
78 " This segment is from the above lines and modified by
|
|
79 " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
|
3830
|
80 " When 'encoding' is utf-8, choose between China (simplified) and Taiwan
|
|
81 " (traditional) based on the language, suggested by Alick Zhao.
|
7
|
82 if s:ext =~? '\.zh'
|
|
83 if &enc =~ 'big5\|cp950'
|
|
84 let s:ext = ".zh.big5"
|
1621
|
85 elseif &enc != 'utf-8'
|
7
|
86 let s:ext = ".zh.euc"
|
3830
|
87 elseif s:ext =~? 'zh_tw' || (exists("s:lang") && s:lang =~? 'zh_tw')
|
|
88 let s:ext = ".zh_tw"
|
|
89 else
|
|
90 let s:ext = ".zh_cn"
|
7
|
91 endif
|
|
92 endif
|
|
93
|
|
94 " The Polish tutor is available in two encodings, guess which one to use.
|
24
|
95 if s:ext =~? '\.pl'
|
|
96 if &enc =~ 1250
|
|
97 let s:ext = ".pl.cp1250"
|
|
98 endif
|
7
|
99 endif
|
|
100
|
557
|
101 " The Turkish tutor is available in two encodings, guess which one to use
|
|
102 if s:ext =~? '\.tr'
|
1621
|
103 if &enc == "iso-8859-9"
|
557
|
104 let s:ext = ".tr.iso9"
|
|
105 endif
|
|
106 endif
|
|
107
|
969
|
108 " The Greek tutor is available in three encodings, guess what to use.
|
|
109 " We used ".gr" (Greece) instead of ".el" (Greek); accept both.
|
|
110 if s:ext =~? '\.gr\|\.el'
|
|
111 if &enc == "iso-8859-7"
|
1621
|
112 let s:ext = ".el"
|
969
|
113 elseif &enc == "utf-8"
|
1621
|
114 let s:ext = ".el.utf-8"
|
969
|
115 elseif &enc =~ 737
|
1621
|
116 let s:ext = ".el.cp737"
|
969
|
117 endif
|
7
|
118 endif
|
|
119
|
1154
|
120 " The Slovak tutor is available in three encodings, guess which one to use
|
|
121 if s:ext =~? '\.sk'
|
1621
|
122 if &enc =~ 1250
|
1154
|
123 let s:ext = ".sk.cp1250"
|
|
124 endif
|
|
125 endif
|
|
126
|
6009
|
127 " The Slovak tutor is available in two encodings, guess which one to use
|
|
128 " Note that the utf-8 version is the original, the cp1250 version is created
|
|
129 " from it.
|
|
130 if s:ext =~? '\.sr'
|
|
131 if &enc =~ 1250
|
|
132 let s:ext = ".sr.cp1250"
|
|
133 endif
|
|
134 endif
|
|
135
|
1154
|
136 " The Czech tutor is available in three encodings, guess which one to use
|
|
137 if s:ext =~? '\.cs'
|
1621
|
138 if &enc =~ 1250
|
1154
|
139 let s:ext = ".cs.cp1250"
|
|
140 endif
|
7
|
141 endif
|
|
142
|
953
|
143 " The Russian tutor is available in three encodings, guess which one to use.
|
|
144 if s:ext =~? '\.ru'
|
1621
|
145 if &enc =~ '1251'
|
953
|
146 let s:ext = '.ru.cp1251'
|
|
147 elseif &enc =~ 'koi8'
|
|
148 let s:ext = '.ru'
|
|
149 endif
|
7
|
150 endif
|
|
151
|
1621
|
152 " The Hungarian tutor is available in three encodings, guess which one to use.
|
1154
|
153 if s:ext =~? '\.hu'
|
1621
|
154 if &enc =~ 1250
|
|
155 let s:ext = ".hu.cp1250"
|
1154
|
156 elseif &enc =~ 'iso-8859-2'
|
|
157 let s:ext = '.hu'
|
|
158 endif
|
|
159 endif
|
|
160
|
1621
|
161 " The Croatian tutor is available in three encodings, guess which one to use.
|
|
162 if s:ext =~? '\.hr'
|
|
163 if &enc =~ 1250
|
|
164 let s:ext = ".hr.cp1250"
|
|
165 elseif &enc =~ 'iso-8859-2'
|
|
166 let s:ext = '.hr'
|
|
167 endif
|
7
|
168 endif
|
|
169
|
1621
|
170 " Esperanto is only available in utf-8
|
|
171 if s:ext =~? '\.eo'
|
|
172 let s:ext = ".eo.utf-8"
|
|
173 endif
|
|
174 " Vietnamese is only available in utf-8
|
|
175 if s:ext =~? '\.vi'
|
|
176 let s:ext = ".vi.utf-8"
|
|
177 endif
|
|
178
|
|
179 " If 'encoding' is utf-8 s:ext must end in utf-8.
|
|
180 if &enc == 'utf-8' && s:ext !~ '\.utf-8'
|
1698
|
181 let s:ext .= '.utf-8'
|
7
|
182 endif
|
|
183
|
|
184 " 2. Build the name of the file:
|
|
185 let s:tutorfile = "/tutor/tutor"
|
|
186 let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
|
|
187
|
|
188 " 3. Finding the file:
|
|
189 if filereadable(s:tutorxx)
|
|
190 let $TUTOR = s:tutorxx
|
|
191 else
|
|
192 let $TUTOR = $VIMRUNTIME . s:tutorfile
|
|
193 echo "The file " . s:tutorxx . " does not exist.\n"
|
|
194 echo "Copying English version: " . $TUTOR
|
|
195 4sleep
|
|
196 endif
|
|
197
|
|
198 " 4. Making the copy and exiting Vim:
|
|
199 e $TUTOR
|
|
200 wq! $TUTORCOPY
|