blob: 3dda1ea0eac43125438d99a163d0f718148f47bc [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 Moolenaard7afed32007-05-06 13:26:41 +00003" Last Change: 2007 Mar 01
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
48" The japanese tutor is available in two encodings, guess which one to use
49" The "sjis" one is actually "cp932", it doesn't matter for this text.
50if s:ext =~? '\.ja'
51 if &enc =~ "euc"
52 let s:ext = ".ja.euc"
53 elseif &enc =~ "utf-8$"
54 let s:ext = ".ja.utf-8"
55 else
56 let s:ext = ".ja.sjis"
57 endif
58endif
59
60" The korean tutor is available in two encodings, guess which one to use
61if s:ext =~? '\.ko'
62 if &enc =~ "utf-8$"
63 let s:ext = ".ko.utf-8"
64 else
65 let s:ext = ".ko.euc"
66 endif
67endif
68
69" The Chinese tutor is available in two encodings, guess which one to use
70" This segment is from the above lines and modified by
71" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
72if s:ext =~? '\.zh'
73 if &enc =~ 'big5\|cp950'
74 let s:ext = ".zh.big5"
75 else
76 let s:ext = ".zh.euc"
77 endif
78endif
79
80" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000081if s:ext =~? '\.pl'
82 if &enc =~ 1250
83 let s:ext = ".pl.cp1250"
84 elseif &enc =~ "utf-8$"
85 let s:ext = ".pl.utf-8"
86 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000087endif
88
Bram Moolenaara5792f52005-11-23 21:25:05 +000089" The Turkish tutor is available in two encodings, guess which one to use
90if s:ext =~? '\.tr'
91 if &enc == "utf-8"
92 let s:ext = ".tr.utf-8"
93 elseif &enc == "iso-8859-9"
94 let s:ext = ".tr.iso9"
95 endif
96endif
97
Bram Moolenaar45125092006-09-10 11:24:31 +000098" The Greek tutor is available in three encodings, guess what to use.
99" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
100if s:ext =~? '\.gr\|\.el'
101 if &enc == "iso-8859-7"
102 let s:ext = ".gr"
103 elseif &enc == "utf-8"
104 let s:ext = ".gr.utf-8"
105 elseif &enc =~ 737
106 let s:ext = ".gr.cp737"
107 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108endif
109
Bram Moolenaard7afed32007-05-06 13:26:41 +0000110" The Slovak tutor is available in three encodings, guess which one to use
111if s:ext =~? '\.sk'
112 if &enc == 'utf-8'
113 let s:ext = ".sk.utf-8"
114 elseif &enc =~ 1250
115 let s:ext = ".sk.cp1250"
116 endif
117endif
118
119" The Czech tutor is available in three encodings, guess which one to use
120if s:ext =~? '\.cs'
121 if &enc == 'utf-8'
122 let s:ext = ".cs.utf-8"
123 elseif &enc =~ 1250
124 let s:ext = ".cs.cp1250"
125 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126endif
127
Bram Moolenaard9380f52006-09-02 12:50:52 +0000128" The Russian tutor is available in three encodings, guess which one to use.
129if s:ext =~? '\.ru'
130 if &enc == 'utf-8'
131 let s:ext = '.ru.utf-8'
132 elseif &enc =~ '1251'
133 let s:ext = '.ru.cp1251'
134 elseif &enc =~ 'koi8'
135 let s:ext = '.ru'
136 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137endif
138
Bram Moolenaard7afed32007-05-06 13:26:41 +0000139" The Hungarian tutor is available in two encodings, guess which one to use.
140if s:ext =~? '\.hu'
141 if &enc == 'utf-8'
142 let s:ext = '.hu.utf-8'
143 elseif &enc =~ 'iso-8859-2'
144 let s:ext = '.hu'
145 endif
146endif
147
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
149if s:ext =~? '\.ge'
150 let s:ext = ".de"
151endif
152
153if s:ext =~? '\.en'
154 let s:ext = ""
155endif
156
157" 2. Build the name of the file:
158let s:tutorfile = "/tutor/tutor"
159let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
160
161" 3. Finding the file:
162if filereadable(s:tutorxx)
163 let $TUTOR = s:tutorxx
164else
165 let $TUTOR = $VIMRUNTIME . s:tutorfile
166 echo "The file " . s:tutorxx . " does not exist.\n"
167 echo "Copying English version: " . $TUTOR
168 4sleep
169endif
170
171" 4. Making the copy and exiting Vim:
172e $TUTOR
173wq! $TUTORCOPY