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