blob: c319e009d4dfbdd16a11035f8357579c85c0ae53 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim tutor support file
2" Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es>
Bram Moolenaare37d50a2008-08-06 17:06:04 +00003" Maintainer: Bram Moolenaar
Bram Moolenaar946e27a2014-06-25 18:50:27 +02004" Last Change: 2014 Jun 25
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006" This Vim script is used for detecting if a translation of the
Bram Moolenaar071d4272004-06-13 20:20:40 +00007" 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:
14let s:ext = ""
15if strlen($xx) > 1
16 let s:ext = "." . $xx
17else
18 let s:lang = ""
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000019 " Check that a potential value has at least two letters.
20 " Ignore "1043" and "C".
21 if exists("v:lang") && v:lang =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000022 let s:lang = v:lang
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000023 elseif $LC_ALL =~ '\a\a'
Bram Moolenaare2cc9702005-03-15 22:43:58 +000024 let s:lang = $LC_ALL
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000025 elseif $LANG =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 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"
Bram Moolenaar946e27a2014-06-25 18:50:27 +020039 elseif s:lang =~ "Serbian"
40 let s:ext = ".sr"
Bram Moolenaard7afed32007-05-06 13:26:41 +000041 elseif s:lang =~ "Czech"
42 let s:ext = ".cs"
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000043 elseif s:lang =~ "Dutch"
44 let s:ext = ".nl"
Bram Moolenaar071d4272004-06-13 20:20:40 +000045 else
46 let s:ext = "." . strpart(s:lang, 0, 2)
47 endif
48 endif
49endif
50
Bram Moolenaar446cb832008-06-24 21:56:24 +000051" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
52if s:ext =~? '\.ge'
53 let s:ext = ".de"
54endif
55
56if s:ext =~? '\.en'
57 let s:ext = ""
58endif
59
Bram Moolenaar071d4272004-06-13 20:20:40 +000060" 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.
62if s:ext =~? '\.ja'
63 if &enc =~ "euc"
64 let s:ext = ".ja.euc"
Bram Moolenaar446cb832008-06-24 21:56:24 +000065 elseif &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000066 let s:ext = ".ja.sjis"
67 endif
68endif
69
70" The korean tutor is available in two encodings, guess which one to use
71if s:ext =~? '\.ko'
Bram Moolenaar446cb832008-06-24 21:56:24 +000072 if &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000073 let s:ext = ".ko.euc"
74 endif
75endif
76
Bram Moolenaard09acef2012-09-21 14:54:30 +020077" The Chinese tutor is available in three encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000078" This segment is from the above lines and modified by
79" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
Bram Moolenaard09acef2012-09-21 14:54:30 +020080" When 'encoding' is utf-8, choose between China (simplified) and Taiwan
81" (traditional) based on the language, suggested by Alick Zhao.
Bram Moolenaar071d4272004-06-13 20:20:40 +000082if s:ext =~? '\.zh'
83 if &enc =~ 'big5\|cp950'
84 let s:ext = ".zh.big5"
Bram Moolenaar446cb832008-06-24 21:56:24 +000085 elseif &enc != 'utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +000086 let s:ext = ".zh.euc"
Bram Moolenaard09acef2012-09-21 14:54:30 +020087 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"
Bram Moolenaar071d4272004-06-13 20:20:40 +000091 endif
92endif
93
94" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000095if s:ext =~? '\.pl'
96 if &enc =~ 1250
97 let s:ext = ".pl.cp1250"
Bram Moolenaarc0197e22004-09-13 20:26:32 +000098 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000099endif
100
Bram Moolenaara5792f52005-11-23 21:25:05 +0000101" The Turkish tutor is available in two encodings, guess which one to use
102if s:ext =~? '\.tr'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000103 if &enc == "iso-8859-9"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000104 let s:ext = ".tr.iso9"
105 endif
106endif
107
Bram Moolenaar45125092006-09-10 11:24:31 +0000108" The Greek tutor is available in three encodings, guess what to use.
109" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
110if s:ext =~? '\.gr\|\.el'
111 if &enc == "iso-8859-7"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000112 let s:ext = ".el"
Bram Moolenaar45125092006-09-10 11:24:31 +0000113 elseif &enc == "utf-8"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000114 let s:ext = ".el.utf-8"
Bram Moolenaar45125092006-09-10 11:24:31 +0000115 elseif &enc =~ 737
Bram Moolenaar446cb832008-06-24 21:56:24 +0000116 let s:ext = ".el.cp737"
Bram Moolenaar45125092006-09-10 11:24:31 +0000117 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118endif
119
Bram Moolenaard7afed32007-05-06 13:26:41 +0000120" The Slovak tutor is available in three encodings, guess which one to use
121if s:ext =~? '\.sk'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000122 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000123 let s:ext = ".sk.cp1250"
124 endif
125endif
126
Bram Moolenaar946e27a2014-06-25 18:50:27 +0200127" 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.
130if s:ext =~? '\.sr'
131 if &enc =~ 1250
132 let s:ext = ".sr.cp1250"
133 endif
134endif
135
Bram Moolenaard7afed32007-05-06 13:26:41 +0000136" The Czech tutor is available in three encodings, guess which one to use
137if s:ext =~? '\.cs'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000138 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000139 let s:ext = ".cs.cp1250"
140 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141endif
142
Bram Moolenaard9380f52006-09-02 12:50:52 +0000143" The Russian tutor is available in three encodings, guess which one to use.
144if s:ext =~? '\.ru'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000145 if &enc =~ '1251'
Bram Moolenaard9380f52006-09-02 12:50:52 +0000146 let s:ext = '.ru.cp1251'
147 elseif &enc =~ 'koi8'
148 let s:ext = '.ru'
149 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150endif
151
Bram Moolenaar446cb832008-06-24 21:56:24 +0000152" The Hungarian tutor is available in three encodings, guess which one to use.
Bram Moolenaard7afed32007-05-06 13:26:41 +0000153if s:ext =~? '\.hu'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000154 if &enc =~ 1250
155 let s:ext = ".hu.cp1250"
Bram Moolenaard7afed32007-05-06 13:26:41 +0000156 elseif &enc =~ 'iso-8859-2'
157 let s:ext = '.hu'
158 endif
159endif
160
Bram Moolenaar446cb832008-06-24 21:56:24 +0000161" The Croatian tutor is available in three encodings, guess which one to use.
162if 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168endif
169
Bram Moolenaar446cb832008-06-24 21:56:24 +0000170" Esperanto is only available in utf-8
171if s:ext =~? '\.eo'
172 let s:ext = ".eo.utf-8"
173endif
174" Vietnamese is only available in utf-8
175if s:ext =~? '\.vi'
176 let s:ext = ".vi.utf-8"
177endif
178
179" If 'encoding' is utf-8 s:ext must end in utf-8.
180if &enc == 'utf-8' && s:ext !~ '\.utf-8'
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000181 let s:ext .= '.utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000182endif
183
184" 2. Build the name of the file:
185let s:tutorfile = "/tutor/tutor"
186let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
187
188" 3. Finding the file:
189if filereadable(s:tutorxx)
190 let $TUTOR = s:tutorxx
191else
192 let $TUTOR = $VIMRUNTIME . s:tutorfile
193 echo "The file " . s:tutorxx . " does not exist.\n"
194 echo "Copying English version: " . $TUTOR
195 4sleep
196endif
197
198" 4. Making the copy and exiting Vim:
199e $TUTOR
200wq! $TUTORCOPY