blob: 29eda4c379e8ec458fe60eb26f61746c57d4bbf9 [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 Moolenaara5792f52005-11-23 21:25:05 +00003" Last Change: 2005 Oct 16
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 Moolenaare2cc9702005-03-15 22:43:58 +000018 if exists("v:lang")
Bram Moolenaar071d4272004-06-13 20:20:40 +000019 let s:lang = v:lang
Bram Moolenaare2cc9702005-03-15 22:43:58 +000020 elseif strlen($LC_ALL) > 0
21 let s:lang = $LC_ALL
22 elseif strlen($LANG) > 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000023 let s:lang = $LANG
24 endif
Bram Moolenaare2cc9702005-03-15 22:43:58 +000025 if s:lang == "C"
26 let s:lang = ""
27 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000028 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 else
40 let s:ext = "." . strpart(s:lang, 0, 2)
41 endif
42 endif
43endif
44
45" The japanese tutor is available in two encodings, guess which one to use
46" The "sjis" one is actually "cp932", it doesn't matter for this text.
47if s:ext =~? '\.ja'
48 if &enc =~ "euc"
49 let s:ext = ".ja.euc"
50 elseif &enc =~ "utf-8$"
51 let s:ext = ".ja.utf-8"
52 else
53 let s:ext = ".ja.sjis"
54 endif
55endif
56
57" The korean tutor is available in two encodings, guess which one to use
58if s:ext =~? '\.ko'
59 if &enc =~ "utf-8$"
60 let s:ext = ".ko.utf-8"
61 else
62 let s:ext = ".ko.euc"
63 endif
64endif
65
66" The Chinese tutor is available in two encodings, guess which one to use
67" This segment is from the above lines and modified by
68" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
69if s:ext =~? '\.zh'
70 if &enc =~ 'big5\|cp950'
71 let s:ext = ".zh.big5"
72 else
73 let s:ext = ".zh.euc"
74 endif
75endif
76
77" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000078if s:ext =~? '\.pl'
79 if &enc =~ 1250
80 let s:ext = ".pl.cp1250"
81 elseif &enc =~ "utf-8$"
82 let s:ext = ".pl.utf-8"
83 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000084endif
85
Bram Moolenaara5792f52005-11-23 21:25:05 +000086" The Turkish tutor is available in two encodings, guess which one to use
87if s:ext =~? '\.tr'
88 if &enc == "utf-8"
89 let s:ext = ".tr.utf-8"
90 elseif &enc == "iso-8859-9"
91 let s:ext = ".tr.iso9"
92 endif
93endif
94
Bram Moolenaar071d4272004-06-13 20:20:40 +000095" The Greek tutor is available in two encodings, guess which one to use
96if s:ext =~? '\.gr' && &enc =~ 737
97 let s:ext = ".gr.cp737"
98endif
99
100" The Slovak tutor is available in two encodings, guess which one to use
101if s:ext =~? '\.sk' && &enc =~ 1250
102 let s:ext = ".sk.cp1250"
103endif
104
105" The Russian tutor is available in two encodings, guess which one to use.
106" This segment is from the above lines and modified by
107" Alexey I. Froloff <raorn@altlinux.org> for Russian vim tutorial
108if s:ext =~? '\.ru' && &enc =~ 1251
109 let s:ext = ".ru.cp1251"
110endif
111
112" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
113if s:ext =~? '\.ge'
114 let s:ext = ".de"
115endif
116
117if s:ext =~? '\.en'
118 let s:ext = ""
119endif
120
121" 2. Build the name of the file:
122let s:tutorfile = "/tutor/tutor"
123let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
124
125" 3. Finding the file:
126if filereadable(s:tutorxx)
127 let $TUTOR = s:tutorxx
128else
129 let $TUTOR = $VIMRUNTIME . s:tutorfile
130 echo "The file " . s:tutorxx . " does not exist.\n"
131 echo "Copying English version: " . $TUTOR
132 4sleep
133endif
134
135" 4. Making the copy and exiting Vim:
136e $TUTOR
137wq! $TUTORCOPY