blob: 9770716f129742881f902d22b02696a615fac0a0 [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 Moolenaard9380f52006-09-02 12:50:52 +00003" Last Change: 2006 Sep 02
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 Moolenaar97b2ad32006-03-18 21:40:56 +000038 elseif s:lang =~ "Dutch"
39 let s:ext = ".nl"
Bram Moolenaar071d4272004-06-13 20:20:40 +000040 else
41 let s:ext = "." . strpart(s:lang, 0, 2)
42 endif
43 endif
44endif
45
46" The japanese tutor is available in two encodings, guess which one to use
47" The "sjis" one is actually "cp932", it doesn't matter for this text.
48if s:ext =~? '\.ja'
49 if &enc =~ "euc"
50 let s:ext = ".ja.euc"
51 elseif &enc =~ "utf-8$"
52 let s:ext = ".ja.utf-8"
53 else
54 let s:ext = ".ja.sjis"
55 endif
56endif
57
58" The korean tutor is available in two encodings, guess which one to use
59if s:ext =~? '\.ko'
60 if &enc =~ "utf-8$"
61 let s:ext = ".ko.utf-8"
62 else
63 let s:ext = ".ko.euc"
64 endif
65endif
66
67" The Chinese tutor is available in two encodings, guess which one to use
68" This segment is from the above lines and modified by
69" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
70if s:ext =~? '\.zh'
71 if &enc =~ 'big5\|cp950'
72 let s:ext = ".zh.big5"
73 else
74 let s:ext = ".zh.euc"
75 endif
76endif
77
78" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000079if s:ext =~? '\.pl'
80 if &enc =~ 1250
81 let s:ext = ".pl.cp1250"
82 elseif &enc =~ "utf-8$"
83 let s:ext = ".pl.utf-8"
84 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000085endif
86
Bram Moolenaara5792f52005-11-23 21:25:05 +000087" The Turkish tutor is available in two encodings, guess which one to use
88if s:ext =~? '\.tr'
89 if &enc == "utf-8"
90 let s:ext = ".tr.utf-8"
91 elseif &enc == "iso-8859-9"
92 let s:ext = ".tr.iso9"
93 endif
94endif
95
Bram Moolenaar071d4272004-06-13 20:20:40 +000096" The Greek tutor is available in two encodings, guess which one to use
97if s:ext =~? '\.gr' && &enc =~ 737
98 let s:ext = ".gr.cp737"
99endif
100
101" The Slovak tutor is available in two encodings, guess which one to use
102if s:ext =~? '\.sk' && &enc =~ 1250
103 let s:ext = ".sk.cp1250"
104endif
105
Bram Moolenaard9380f52006-09-02 12:50:52 +0000106" The Russian tutor is available in three encodings, guess which one to use.
107if s:ext =~? '\.ru'
108 if &enc == 'utf-8'
109 let s:ext = '.ru.utf-8'
110 elseif &enc =~ '1251'
111 let s:ext = '.ru.cp1251'
112 elseif &enc =~ 'koi8'
113 let s:ext = '.ru'
114 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115endif
116
117" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
118if s:ext =~? '\.ge'
119 let s:ext = ".de"
120endif
121
122if s:ext =~? '\.en'
123 let s:ext = ""
124endif
125
126" 2. Build the name of the file:
127let s:tutorfile = "/tutor/tutor"
128let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
129
130" 3. Finding the file:
131if filereadable(s:tutorxx)
132 let $TUTOR = s:tutorxx
133else
134 let $TUTOR = $VIMRUNTIME . s:tutorfile
135 echo "The file " . s:tutorxx . " does not exist.\n"
136 echo "Copying English version: " . $TUTOR
137 4sleep
138endif
139
140" 4. Making the copy and exiting Vim:
141e $TUTOR
142wq! $TUTORCOPY