blob: 7c3ea50df5c23c093147f1345a89380e18bfd35a [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 Moolenaar45125092006-09-10 11:24:31 +00003" Last Change: 2006 Sep 09
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 Moolenaar45125092006-09-10 11:24:31 +000096" The Greek tutor is available in three encodings, guess what to use.
97" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
98if s:ext =~? '\.gr\|\.el'
99 if &enc == "iso-8859-7"
100 let s:ext = ".gr"
101 elseif &enc == "utf-8"
102 let s:ext = ".gr.utf-8"
103 elseif &enc =~ 737
104 let s:ext = ".gr.cp737"
105 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106endif
107
108" The Slovak tutor is available in two encodings, guess which one to use
109if s:ext =~? '\.sk' && &enc =~ 1250
110 let s:ext = ".sk.cp1250"
111endif
112
Bram Moolenaard9380f52006-09-02 12:50:52 +0000113" The Russian tutor is available in three encodings, guess which one to use.
114if s:ext =~? '\.ru'
115 if &enc == 'utf-8'
116 let s:ext = '.ru.utf-8'
117 elseif &enc =~ '1251'
118 let s:ext = '.ru.cp1251'
119 elseif &enc =~ 'koi8'
120 let s:ext = '.ru'
121 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122endif
123
124" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
125if s:ext =~? '\.ge'
126 let s:ext = ".de"
127endif
128
129if s:ext =~? '\.en'
130 let s:ext = ""
131endif
132
133" 2. Build the name of the file:
134let s:tutorfile = "/tutor/tutor"
135let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
136
137" 3. Finding the file:
138if filereadable(s:tutorxx)
139 let $TUTOR = s:tutorxx
140else
141 let $TUTOR = $VIMRUNTIME . s:tutorfile
142 echo "The file " . s:tutorxx . " does not exist.\n"
143 echo "Copying English version: " . $TUTOR
144 4sleep
145endif
146
147" 4. Making the copy and exiting Vim:
148e $TUTOR
149wq! $TUTORCOPY