blob: a48ff6a4ebb461362505d76b6f31e345a7c66232 [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 Moolenaard09acef2012-09-21 14:54:30 +02004" Last Change: 2012 Sep 21
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 Moolenaard7afed32007-05-06 13:26:41 +000039 elseif s:lang =~ "Czech"
40 let s:ext = ".cs"
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000041 elseif s:lang =~ "Dutch"
42 let s:ext = ".nl"
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 else
44 let s:ext = "." . strpart(s:lang, 0, 2)
45 endif
46 endif
47endif
48
Bram Moolenaar446cb832008-06-24 21:56:24 +000049" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
50if s:ext =~? '\.ge'
51 let s:ext = ".de"
52endif
53
54if s:ext =~? '\.en'
55 let s:ext = ""
56endif
57
Bram Moolenaar071d4272004-06-13 20:20:40 +000058" 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.
60if s:ext =~? '\.ja'
61 if &enc =~ "euc"
62 let s:ext = ".ja.euc"
Bram Moolenaar446cb832008-06-24 21:56:24 +000063 elseif &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000064 let s:ext = ".ja.sjis"
65 endif
66endif
67
68" The korean tutor is available in two encodings, guess which one to use
69if s:ext =~? '\.ko'
Bram Moolenaar446cb832008-06-24 21:56:24 +000070 if &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000071 let s:ext = ".ko.euc"
72 endif
73endif
74
Bram Moolenaard09acef2012-09-21 14:54:30 +020075" The Chinese tutor is available in three encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000076" This segment is from the above lines and modified by
77" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
Bram Moolenaard09acef2012-09-21 14:54:30 +020078" When 'encoding' is utf-8, choose between China (simplified) and Taiwan
79" (traditional) based on the language, suggested by Alick Zhao.
Bram Moolenaar071d4272004-06-13 20:20:40 +000080if s:ext =~? '\.zh'
81 if &enc =~ 'big5\|cp950'
82 let s:ext = ".zh.big5"
Bram Moolenaar446cb832008-06-24 21:56:24 +000083 elseif &enc != 'utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +000084 let s:ext = ".zh.euc"
Bram Moolenaard09acef2012-09-21 14:54:30 +020085 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"
Bram Moolenaar071d4272004-06-13 20:20:40 +000089 endif
90endif
91
92" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000093if s:ext =~? '\.pl'
94 if &enc =~ 1250
95 let s:ext = ".pl.cp1250"
Bram Moolenaarc0197e22004-09-13 20:26:32 +000096 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000097endif
98
Bram Moolenaara5792f52005-11-23 21:25:05 +000099" The Turkish tutor is available in two encodings, guess which one to use
100if s:ext =~? '\.tr'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000101 if &enc == "iso-8859-9"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000102 let s:ext = ".tr.iso9"
103 endif
104endif
105
Bram Moolenaar45125092006-09-10 11:24:31 +0000106" The Greek tutor is available in three encodings, guess what to use.
107" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
108if s:ext =~? '\.gr\|\.el'
109 if &enc == "iso-8859-7"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000110 let s:ext = ".el"
Bram Moolenaar45125092006-09-10 11:24:31 +0000111 elseif &enc == "utf-8"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000112 let s:ext = ".el.utf-8"
Bram Moolenaar45125092006-09-10 11:24:31 +0000113 elseif &enc =~ 737
Bram Moolenaar446cb832008-06-24 21:56:24 +0000114 let s:ext = ".el.cp737"
Bram Moolenaar45125092006-09-10 11:24:31 +0000115 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116endif
117
Bram Moolenaard7afed32007-05-06 13:26:41 +0000118" The Slovak tutor is available in three encodings, guess which one to use
119if s:ext =~? '\.sk'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000120 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000121 let s:ext = ".sk.cp1250"
122 endif
123endif
124
125" The Czech tutor is available in three encodings, guess which one to use
126if s:ext =~? '\.cs'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000127 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000128 let s:ext = ".cs.cp1250"
129 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130endif
131
Bram Moolenaard9380f52006-09-02 12:50:52 +0000132" The Russian tutor is available in three encodings, guess which one to use.
133if s:ext =~? '\.ru'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000134 if &enc =~ '1251'
Bram Moolenaard9380f52006-09-02 12:50:52 +0000135 let s:ext = '.ru.cp1251'
136 elseif &enc =~ 'koi8'
137 let s:ext = '.ru'
138 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139endif
140
Bram Moolenaar446cb832008-06-24 21:56:24 +0000141" The Hungarian tutor is available in three encodings, guess which one to use.
Bram Moolenaard7afed32007-05-06 13:26:41 +0000142if s:ext =~? '\.hu'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000143 if &enc =~ 1250
144 let s:ext = ".hu.cp1250"
Bram Moolenaard7afed32007-05-06 13:26:41 +0000145 elseif &enc =~ 'iso-8859-2'
146 let s:ext = '.hu'
147 endif
148endif
149
Bram Moolenaar446cb832008-06-24 21:56:24 +0000150" The Croatian tutor is available in three encodings, guess which one to use.
151if 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157endif
158
Bram Moolenaar446cb832008-06-24 21:56:24 +0000159" Esperanto is only available in utf-8
160if s:ext =~? '\.eo'
161 let s:ext = ".eo.utf-8"
162endif
163" Vietnamese is only available in utf-8
164if s:ext =~? '\.vi'
165 let s:ext = ".vi.utf-8"
166endif
167
168" If 'encoding' is utf-8 s:ext must end in utf-8.
169if &enc == 'utf-8' && s:ext !~ '\.utf-8'
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000170 let s:ext .= '.utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171endif
172
173" 2. Build the name of the file:
174let s:tutorfile = "/tutor/tutor"
175let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
176
177" 3. Finding the file:
178if filereadable(s:tutorxx)
179 let $TUTOR = s:tutorxx
180else
181 let $TUTOR = $VIMRUNTIME . s:tutorfile
182 echo "The file " . s:tutorxx . " does not exist.\n"
183 echo "Copying English version: " . $TUTOR
184 4sleep
185endif
186
187" 4. Making the copy and exiting Vim:
188e $TUTOR
189wq! $TUTORCOPY