Merge branch 'MacVim'
[MacVim/KaoriYa.git] / runtime / tutor / tutor.vim
blob11584d5b75b7baa668e3da3bd6c4ea27e87846d3
1 " Vim tutor support file
2 " Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es>
3 " Maintainer: Bram Moolenaar
4 " Last Change:  2008 Jul 21
6 " This Vim script is used for detecting if a translation of the
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.
11 " It is invoked by the vimtutor shell script.
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 = ""
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'
22     let s:lang = v:lang
23   elseif $LC_ALL =~ '\a\a'
24     let s:lang = $LC_ALL
25   elseif $LANG =~ '\a\a'
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"
39     elseif s:lang =~ "Czech"
40       let s:ext = ".cs"
41     elseif s:lang =~ "Dutch"
42       let s:ext = ".nl"
43     else
44       let s:ext = "." . strpart(s:lang, 0, 2)
45     endif
46   endif
47 endif
49 " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
50 if s:ext =~? '\.ge'
51   let s:ext = ".de"
52 endif
54 if s:ext =~? '\.en'
55   let s:ext = ""
56 endif
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"
63   elseif &enc != "utf-8"
64     let s:ext = ".ja.sjis"
65   endif
66 endif
68 " The korean tutor is available in two encodings, guess which one to use
69 if s:ext =~? '\.ko'
70   if &enc != "utf-8"
71     let s:ext = ".ko.euc"
72   endif
73 endif
75 " The Chinese tutor is available in two encodings, guess which one to use
76 " This segment is from the above lines and modified by
77 " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
78 if s:ext =~? '\.zh'
79   if &enc =~ 'big5\|cp950'
80     let s:ext = ".zh.big5"
81   elseif &enc != 'utf-8'
82     let s:ext = ".zh.euc"
83   endif
84 endif
86 " The Polish tutor is available in two encodings, guess which one to use.
87 if s:ext =~? '\.pl'
88   if &enc =~ 1250
89     let s:ext = ".pl.cp1250"
90   endif
91 endif
93 " The Turkish tutor is available in two encodings, guess which one to use
94 if s:ext =~? '\.tr'
95   if &enc == "iso-8859-9"
96     let s:ext = ".tr.iso9"
97   endif
98 endif
100 " The Greek tutor is available in three encodings, guess what to use.
101 " We used ".gr" (Greece) instead of ".el" (Greek); accept both.
102 if s:ext =~? '\.gr\|\.el'
103   if &enc == "iso-8859-7"
104     let s:ext = ".el"
105   elseif &enc == "utf-8"
106     let s:ext = ".el.utf-8"
107   elseif &enc =~ 737
108     let s:ext = ".el.cp737"
109   endif
110 endif
112 " The Slovak tutor is available in three encodings, guess which one to use
113 if s:ext =~? '\.sk'
114   if &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 =~ 1250
122     let s:ext = ".cs.cp1250"
123   endif
124 endif
126 " The Russian tutor is available in three encodings, guess which one to use.
127 if s:ext =~? '\.ru'
128   if &enc =~ '1251'
129     let s:ext = '.ru.cp1251'
130   elseif &enc =~ 'koi8'
131     let s:ext = '.ru'
132   endif
133 endif
135 " The Hungarian tutor is available in three encodings, guess which one to use.
136 if s:ext =~? '\.hu'
137   if &enc =~ 1250
138     let s:ext = ".hu.cp1250"
139   elseif &enc =~ 'iso-8859-2'
140     let s:ext = '.hu'
141   endif
142 endif
144 " The Croatian tutor is available in three encodings, guess which one to use.
145 if s:ext =~? '\.hr'
146   if &enc =~ 1250
147     let s:ext = ".hr.cp1250"
148   elseif &enc =~ 'iso-8859-2'
149     let s:ext = '.hr'
150   endif
151 endif
153 " Esperanto is only available in utf-8
154 if s:ext =~? '\.eo'
155   let s:ext = ".eo.utf-8"
156 endif
157 " Vietnamese is only available in utf-8
158 if s:ext =~? '\.vi'
159   let s:ext = ".vi.utf-8"
160 endif
162 " If 'encoding' is utf-8 s:ext must end in utf-8.
163 if &enc == 'utf-8' && s:ext !~ '\.utf-8'
164   let s:ext .= '.utf-8'
165 endif
167 " 2. Build the name of the file:
168 let s:tutorfile = "/tutor/tutor"
169 let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
171 " 3. Finding the file:
172 if filereadable(s:tutorxx)
173   let $TUTOR = s:tutorxx
174 else
175   let $TUTOR = $VIMRUNTIME . s:tutorfile
176   echo "The file " . s:tutorxx . " does not exist.\n"
177   echo "Copying English version: " . $TUTOR
178   4sleep
179 endif
181 " 4. Making the copy and exiting Vim:
182 e $TUTOR
183 wq! $TUTORCOPY