xref: /vim-8.2.3635/runtime/tutor/tutor.vim (revision f4cd3e80)
1" Vim tutor support file
2" Author: Eduardo F. Amatria <[email protected]>
3" Last Change:	2005 Oct 16
4
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 = ""
18  if exists("v:lang")
19    let s:lang = v:lang
20  elseif strlen($LC_ALL) > 0
21    let s:lang = $LC_ALL
22  elseif strlen($LANG) > 0
23    let s:lang = $LANG
24  endif
25  if s:lang == "C"
26    let s:lang = ""
27  endif
28  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 <[email protected]> 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.
78if 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
84endif
85
86" 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
95" 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 <[email protected]> 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
138