7
|
1 " Vim tutor support file
|
|
2 " Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es>
|
1698
|
3 " Maintainer: Bram Moolenaar
|
3830
|
4 " Last Change: 2012 Sep 21
|
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"
|
1154
|
39 elseif s:lang =~ "Czech"
|
|
40 let s:ext = ".cs"
|
782
|
41 elseif s:lang =~ "Dutch"
|
|
42 let s:ext = ".nl"
|
7
|
43 else
|
|
44 let s:ext = "." . strpart(s:lang, 0, 2)
|
|
45 endif
|
|
46 endif
|
|
47 endif
|
|
48
|
1621
|
49 " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
|
|
50 if s:ext =~? '\.ge'
|
|
51 let s:ext = ".de"
|
|
52 endif
|
|
53
|
|
54 if s:ext =~? '\.en'
|
|
55 let s:ext = ""
|
|
56 endif
|
|
57
|
7
|
58 " The japanese tutor is available in two encodings, guess which one to use
|
|
59 " The "sjis" one is actually "cp932", it doesn't matter for this text.
|
|
60 if s:ext =~? '\.ja'
|
|
61 if &enc =~ "euc"
|
|
62 let s:ext = ".ja.euc"
|
1621
|
63 elseif &enc != "utf-8"
|
7
|
64 let s:ext = ".ja.sjis"
|
|
65 endif
|
|
66 endif
|
|
67
|
|
68 " The korean tutor is available in two encodings, guess which one to use
|
|
69 if s:ext =~? '\.ko'
|
1621
|
70 if &enc != "utf-8"
|
7
|
71 let s:ext = ".ko.euc"
|
|
72 endif
|
|
73 endif
|
|
74
|
3830
|
75 " The Chinese tutor is available in three encodings, guess which one to use
|
7
|
76 " This segment is from the above lines and modified by
|
|
77 " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
|
3830
|
78 " When 'encoding' is utf-8, choose between China (simplified) and Taiwan
|
|
79 " (traditional) based on the language, suggested by Alick Zhao.
|
7
|
80 if s:ext =~? '\.zh'
|
|
81 if &enc =~ 'big5\|cp950'
|
|
82 let s:ext = ".zh.big5"
|
1621
|
83 elseif &enc != 'utf-8'
|
7
|
84 let s:ext = ".zh.euc"
|
3830
|
85 elseif s:ext =~? 'zh_tw' || (exists("s:lang") && s:lang =~? 'zh_tw')
|
|
86 let s:ext = ".zh_tw"
|
|
87 else
|
|
88 let s:ext = ".zh_cn"
|
7
|
89 endif
|
|
90 endif
|
|
91
|
|
92 " The Polish tutor is available in two encodings, guess which one to use.
|
24
|
93 if s:ext =~? '\.pl'
|
|
94 if &enc =~ 1250
|
|
95 let s:ext = ".pl.cp1250"
|
|
96 endif
|
7
|
97 endif
|
|
98
|
557
|
99 " The Turkish tutor is available in two encodings, guess which one to use
|
|
100 if s:ext =~? '\.tr'
|
1621
|
101 if &enc == "iso-8859-9"
|
557
|
102 let s:ext = ".tr.iso9"
|
|
103 endif
|
|
104 endif
|
|
105
|
969
|
106 " The Greek tutor is available in three encodings, guess what to use.
|
|
107 " We used ".gr" (Greece) instead of ".el" (Greek); accept both.
|
|
108 if s:ext =~? '\.gr\|\.el'
|
|
109 if &enc == "iso-8859-7"
|
1621
|
110 let s:ext = ".el"
|
969
|
111 elseif &enc == "utf-8"
|
1621
|
112 let s:ext = ".el.utf-8"
|
969
|
113 elseif &enc =~ 737
|
1621
|
114 let s:ext = ".el.cp737"
|
969
|
115 endif
|
7
|
116 endif
|
|
117
|
1154
|
118 " The Slovak tutor is available in three encodings, guess which one to use
|
|
119 if s:ext =~? '\.sk'
|
1621
|
120 if &enc =~ 1250
|
1154
|
121 let s:ext = ".sk.cp1250"
|
|
122 endif
|
|
123 endif
|
|
124
|
|
125 " The Czech tutor is available in three encodings, guess which one to use
|
|
126 if s:ext =~? '\.cs'
|
1621
|
127 if &enc =~ 1250
|
1154
|
128 let s:ext = ".cs.cp1250"
|
|
129 endif
|
7
|
130 endif
|
|
131
|
953
|
132 " The Russian tutor is available in three encodings, guess which one to use.
|
|
133 if s:ext =~? '\.ru'
|
1621
|
134 if &enc =~ '1251'
|
953
|
135 let s:ext = '.ru.cp1251'
|
|
136 elseif &enc =~ 'koi8'
|
|
137 let s:ext = '.ru'
|
|
138 endif
|
7
|
139 endif
|
|
140
|
1621
|
141 " The Hungarian tutor is available in three encodings, guess which one to use.
|
1154
|
142 if s:ext =~? '\.hu'
|
1621
|
143 if &enc =~ 1250
|
|
144 let s:ext = ".hu.cp1250"
|
1154
|
145 elseif &enc =~ 'iso-8859-2'
|
|
146 let s:ext = '.hu'
|
|
147 endif
|
|
148 endif
|
|
149
|
1621
|
150 " The Croatian tutor is available in three encodings, guess which one to use.
|
|
151 if s:ext =~? '\.hr'
|
|
152 if &enc =~ 1250
|
|
153 let s:ext = ".hr.cp1250"
|
|
154 elseif &enc =~ 'iso-8859-2'
|
|
155 let s:ext = '.hr'
|
|
156 endif
|
7
|
157 endif
|
|
158
|
1621
|
159 " Esperanto is only available in utf-8
|
|
160 if s:ext =~? '\.eo'
|
|
161 let s:ext = ".eo.utf-8"
|
|
162 endif
|
|
163 " Vietnamese is only available in utf-8
|
|
164 if s:ext =~? '\.vi'
|
|
165 let s:ext = ".vi.utf-8"
|
|
166 endif
|
|
167
|
|
168 " If 'encoding' is utf-8 s:ext must end in utf-8.
|
|
169 if &enc == 'utf-8' && s:ext !~ '\.utf-8'
|
1698
|
170 let s:ext .= '.utf-8'
|
7
|
171 endif
|
|
172
|
|
173 " 2. Build the name of the file:
|
|
174 let s:tutorfile = "/tutor/tutor"
|
|
175 let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
|
|
176
|
|
177 " 3. Finding the file:
|
|
178 if filereadable(s:tutorxx)
|
|
179 let $TUTOR = s:tutorxx
|
|
180 else
|
|
181 let $TUTOR = $VIMRUNTIME . s:tutorfile
|
|
182 echo "The file " . s:tutorxx . " does not exist.\n"
|
|
183 echo "Copying English version: " . $TUTOR
|
|
184 4sleep
|
|
185 endif
|
|
186
|
|
187 " 4. Making the copy and exiting Vim:
|
|
188 e $TUTOR
|
|
189 wq! $TUTORCOPY
|