blob: 81e5a1919a99e004707bd3c497399e148060e144 [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 Moolenaar446cb832008-06-24 21:56:24 +00003" Last Change: 2008 Jun 21
Bram Moolenaar071d4272004-06-13 20:20:40 +00004
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.
9
10" It is invoked by the vimtutor shell script.
11
12" 1. Build the extension of the file, if any:
13let s:ext = ""
14if strlen($xx) > 1
15 let s:ext = "." . $xx
16else
17 let s:lang = ""
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000018 " Check that a potential value has at least two letters.
19 " Ignore "1043" and "C".
20 if exists("v:lang") && v:lang =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000021 let s:lang = v:lang
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000022 elseif $LC_ALL =~ '\a\a'
Bram Moolenaare2cc9702005-03-15 22:43:58 +000023 let s:lang = $LC_ALL
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000024 elseif $LANG =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000025 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"
Bram Moolenaard7afed32007-05-06 13:26:41 +000038 elseif s:lang =~ "Czech"
39 let s:ext = ".cs"
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000040 elseif s:lang =~ "Dutch"
41 let s:ext = ".nl"
Bram Moolenaar071d4272004-06-13 20:20:40 +000042 else
43 let s:ext = "." . strpart(s:lang, 0, 2)
44 endif
45 endif
46endif
47
Bram Moolenaar446cb832008-06-24 21:56:24 +000048" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
49if s:ext =~? '\.ge'
50 let s:ext = ".de"
51endif
52
53if s:ext =~? '\.en'
54 let s:ext = ""
55endif
56
Bram Moolenaar071d4272004-06-13 20:20:40 +000057" The japanese tutor is available in two encodings, guess which one to use
58" The "sjis" one is actually "cp932", it doesn't matter for this text.
59if s:ext =~? '\.ja'
60 if &enc =~ "euc"
61 let s:ext = ".ja.euc"
Bram Moolenaar446cb832008-06-24 21:56:24 +000062 elseif &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000063 let s:ext = ".ja.sjis"
64 endif
65endif
66
67" The korean tutor is available in two encodings, guess which one to use
68if s:ext =~? '\.ko'
Bram Moolenaar446cb832008-06-24 21:56:24 +000069 if &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000070 let s:ext = ".ko.euc"
71 endif
72endif
73
74" The Chinese tutor is available in two encodings, guess which one to use
75" This segment is from the above lines and modified by
76" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
77if s:ext =~? '\.zh'
78 if &enc =~ 'big5\|cp950'
79 let s:ext = ".zh.big5"
Bram Moolenaar446cb832008-06-24 21:56:24 +000080 elseif &enc != 'utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +000081 let s:ext = ".zh.euc"
82 endif
83endif
84
85" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000086if s:ext =~? '\.pl'
87 if &enc =~ 1250
88 let s:ext = ".pl.cp1250"
Bram Moolenaarc0197e22004-09-13 20:26:32 +000089 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000090endif
91
Bram Moolenaara5792f52005-11-23 21:25:05 +000092" The Turkish tutor is available in two encodings, guess which one to use
93if s:ext =~? '\.tr'
Bram Moolenaar446cb832008-06-24 21:56:24 +000094 if &enc == "iso-8859-9"
Bram Moolenaara5792f52005-11-23 21:25:05 +000095 let s:ext = ".tr.iso9"
96 endif
97endif
98
Bram Moolenaar45125092006-09-10 11:24:31 +000099" The Greek tutor is available in three encodings, guess what to use.
100" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
101if s:ext =~? '\.gr\|\.el'
102 if &enc == "iso-8859-7"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000103 let s:ext = ".el"
Bram Moolenaar45125092006-09-10 11:24:31 +0000104 elseif &enc == "utf-8"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000105 let s:ext = ".el.utf-8"
Bram Moolenaar45125092006-09-10 11:24:31 +0000106 elseif &enc =~ 737
Bram Moolenaar446cb832008-06-24 21:56:24 +0000107 let s:ext = ".el.cp737"
Bram Moolenaar45125092006-09-10 11:24:31 +0000108 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109endif
110
Bram Moolenaard7afed32007-05-06 13:26:41 +0000111" The Slovak tutor is available in three encodings, guess which one to use
112if s:ext =~? '\.sk'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000113 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000114 let s:ext = ".sk.cp1250"
115 endif
116endif
117
118" The Czech tutor is available in three encodings, guess which one to use
119if s:ext =~? '\.cs'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000120 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000121 let s:ext = ".cs.cp1250"
122 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123endif
124
Bram Moolenaard9380f52006-09-02 12:50:52 +0000125" The Russian tutor is available in three encodings, guess which one to use.
126if s:ext =~? '\.ru'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000127 if &enc =~ '1251'
Bram Moolenaard9380f52006-09-02 12:50:52 +0000128 let s:ext = '.ru.cp1251'
129 elseif &enc =~ 'koi8'
130 let s:ext = '.ru'
131 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132endif
133
Bram Moolenaar446cb832008-06-24 21:56:24 +0000134" The Hungarian tutor is available in three encodings, guess which one to use.
Bram Moolenaard7afed32007-05-06 13:26:41 +0000135if s:ext =~? '\.hu'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000136 if &enc =~ 1250
137 let s:ext = ".hu.cp1250"
Bram Moolenaard7afed32007-05-06 13:26:41 +0000138 elseif &enc =~ 'iso-8859-2'
139 let s:ext = '.hu'
140 endif
141endif
142
Bram Moolenaar446cb832008-06-24 21:56:24 +0000143" The Croatian tutor is available in three encodings, guess which one to use.
144if s:ext =~? '\.hr'
145 if &enc =~ 1250
146 let s:ext = ".hr.cp1250"
147 elseif &enc =~ 'iso-8859-2'
148 let s:ext = '.hr'
149 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150endif
151
Bram Moolenaar446cb832008-06-24 21:56:24 +0000152" Esperanto is only available in utf-8
153if s:ext =~? '\.eo'
154 let s:ext = ".eo.utf-8"
155endif
156" Vietnamese is only available in utf-8
157if s:ext =~? '\.vi'
158 let s:ext = ".vi.utf-8"
159endif
160
161" If 'encoding' is utf-8 s:ext must end in utf-8.
162if &enc == 'utf-8' && s:ext !~ '\.utf-8'
163 s:ext .= '.utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164endif
165
166" 2. Build the name of the file:
167let s:tutorfile = "/tutor/tutor"
168let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
169
170" 3. Finding the file:
171if filereadable(s:tutorxx)
172 let $TUTOR = s:tutorxx
173else
174 let $TUTOR = $VIMRUNTIME . s:tutorfile
175 echo "The file " . s:tutorxx . " does not exist.\n"
176 echo "Copying English version: " . $TUTOR
177 4sleep
178endif
179
180" 4. Making the copy and exiting Vim:
181e $TUTOR
182wq! $TUTORCOPY