blob: f450e773dab1732343b909112fdc7f4b7b0f96b8 [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 Moolenaare37d50a2008-08-06 17:06:04 +00003" Maintainer: Bram Moolenaar
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02004" Last Change: 2018 Apr 11
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006" This Vim script is used for detecting if a translation of the
Bram Moolenaar071d4272004-06-13 20:20:40 +00007" tutor file exist, i.e., a tutor.xx file, where xx is the language.
8" If the translation does not exist, or no extension is given,
Bram Moolenaar7dda86f2018-04-20 22:36:41 +02009" it defaults to the English version.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
11" It is invoked by the vimtutor shell script.
12
13" 1. Build the extension of the file, if any:
14let s:ext = ""
15if strlen($xx) > 1
16 let s:ext = "." . $xx
17else
18 let s:lang = ""
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000019 " Check that a potential value has at least two letters.
20 " Ignore "1043" and "C".
21 if exists("v:lang") && v:lang =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000022 let s:lang = v:lang
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000023 elseif $LC_ALL =~ '\a\a'
Bram Moolenaare2cc9702005-03-15 22:43:58 +000024 let s:lang = $LC_ALL
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000025 elseif $LANG =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 let s:lang = $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"
Bram Moolenaar946e27a2014-06-25 18:50:27 +020039 elseif s:lang =~ "Serbian"
40 let s:ext = ".sr"
Bram Moolenaard7afed32007-05-06 13:26:41 +000041 elseif s:lang =~ "Czech"
42 let s:ext = ".cs"
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000043 elseif s:lang =~ "Dutch"
44 let s:ext = ".nl"
Bram Moolenaar42ebd062016-07-17 13:35:14 +020045 elseif s:lang =~ "Bulgarian"
46 let s:ext = ".bg"
Bram Moolenaar071d4272004-06-13 20:20:40 +000047 else
48 let s:ext = "." . strpart(s:lang, 0, 2)
49 endif
50 endif
51endif
52
Bram Moolenaar446cb832008-06-24 21:56:24 +000053" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
54if s:ext =~? '\.ge'
55 let s:ext = ".de"
56endif
57
58if s:ext =~? '\.en'
59 let s:ext = ""
60endif
61
Bram Moolenaara9604e62018-07-21 05:56:22 +020062" The Japanese tutor is available in three encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000063" The "sjis" one is actually "cp932", it doesn't matter for this text.
64if s:ext =~? '\.ja'
65 if &enc =~ "euc"
66 let s:ext = ".ja.euc"
Bram Moolenaar446cb832008-06-24 21:56:24 +000067 elseif &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 let s:ext = ".ja.sjis"
69 endif
70endif
71
Bram Moolenaara9604e62018-07-21 05:56:22 +020072" The Korean tutor is available in two encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000073if s:ext =~? '\.ko'
Bram Moolenaar446cb832008-06-24 21:56:24 +000074 if &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000075 let s:ext = ".ko.euc"
76 endif
77endif
78
Bram Moolenaard09acef2012-09-21 14:54:30 +020079" The Chinese tutor is available in three encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000080" This segment is from the above lines and modified by
81" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
Bram Moolenaard09acef2012-09-21 14:54:30 +020082" When 'encoding' is utf-8, choose between China (simplified) and Taiwan
83" (traditional) based on the language, suggested by Alick Zhao.
Bram Moolenaar071d4272004-06-13 20:20:40 +000084if s:ext =~? '\.zh'
85 if &enc =~ 'big5\|cp950'
86 let s:ext = ".zh.big5"
Bram Moolenaar446cb832008-06-24 21:56:24 +000087 elseif &enc != 'utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +000088 let s:ext = ".zh.euc"
Bram Moolenaard09acef2012-09-21 14:54:30 +020089 elseif s:ext =~? 'zh_tw' || (exists("s:lang") && s:lang =~? 'zh_tw')
90 let s:ext = ".zh_tw"
91 else
92 let s:ext = ".zh_cn"
Bram Moolenaar071d4272004-06-13 20:20:40 +000093 endif
94endif
95
96" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +000097if s:ext =~? '\.pl'
98 if &enc =~ 1250
99 let s:ext = ".pl.cp1250"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000100 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101endif
102
Bram Moolenaara5792f52005-11-23 21:25:05 +0000103" The Turkish tutor is available in two encodings, guess which one to use
104if s:ext =~? '\.tr'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000105 if &enc == "iso-8859-9"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000106 let s:ext = ".tr.iso9"
107 endif
108endif
109
Bram Moolenaar45125092006-09-10 11:24:31 +0000110" The Greek tutor is available in three encodings, guess what to use.
111" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
112if s:ext =~? '\.gr\|\.el'
113 if &enc == "iso-8859-7"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000114 let s:ext = ".el"
Bram Moolenaar45125092006-09-10 11:24:31 +0000115 elseif &enc == "utf-8"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000116 let s:ext = ".el.utf-8"
Bram Moolenaar45125092006-09-10 11:24:31 +0000117 elseif &enc =~ 737
Bram Moolenaar446cb832008-06-24 21:56:24 +0000118 let s:ext = ".el.cp737"
Bram Moolenaar45125092006-09-10 11:24:31 +0000119 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120endif
121
Bram Moolenaard7afed32007-05-06 13:26:41 +0000122" The Slovak tutor is available in three encodings, guess which one to use
123if s:ext =~? '\.sk'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000124 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000125 let s:ext = ".sk.cp1250"
126 endif
127endif
128
Bram Moolenaar946e27a2014-06-25 18:50:27 +0200129" The Slovak tutor is available in two encodings, guess which one to use
130" Note that the utf-8 version is the original, the cp1250 version is created
131" from it.
132if s:ext =~? '\.sr'
133 if &enc =~ 1250
134 let s:ext = ".sr.cp1250"
135 endif
136endif
137
Bram Moolenaard7afed32007-05-06 13:26:41 +0000138" The Czech tutor is available in three encodings, guess which one to use
139if s:ext =~? '\.cs'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000140 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000141 let s:ext = ".cs.cp1250"
142 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143endif
144
Bram Moolenaard9380f52006-09-02 12:50:52 +0000145" The Russian tutor is available in three encodings, guess which one to use.
146if s:ext =~? '\.ru'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000147 if &enc =~ '1251'
Bram Moolenaard9380f52006-09-02 12:50:52 +0000148 let s:ext = '.ru.cp1251'
149 elseif &enc =~ 'koi8'
150 let s:ext = '.ru'
151 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152endif
153
Bram Moolenaar446cb832008-06-24 21:56:24 +0000154" The Hungarian tutor is available in three encodings, guess which one to use.
Bram Moolenaard7afed32007-05-06 13:26:41 +0000155if s:ext =~? '\.hu'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000156 if &enc =~ 1250
157 let s:ext = ".hu.cp1250"
Bram Moolenaard7afed32007-05-06 13:26:41 +0000158 elseif &enc =~ 'iso-8859-2'
159 let s:ext = '.hu'
160 endif
161endif
162
Bram Moolenaar446cb832008-06-24 21:56:24 +0000163" The Croatian tutor is available in three encodings, guess which one to use.
164if s:ext =~? '\.hr'
165 if &enc =~ 1250
166 let s:ext = ".hr.cp1250"
167 elseif &enc =~ 'iso-8859-2'
168 let s:ext = '.hr'
169 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170endif
171
Bram Moolenaar446cb832008-06-24 21:56:24 +0000172" If 'encoding' is utf-8 s:ext must end in utf-8.
173if &enc == 'utf-8' && s:ext !~ '\.utf-8'
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000174 let s:ext .= '.utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175endif
176
177" 2. Build the name of the file:
178let s:tutorfile = "/tutor/tutor"
179let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
180
181" 3. Finding the file:
182if filereadable(s:tutorxx)
183 let $TUTOR = s:tutorxx
Bram Moolenaara9604e62018-07-21 05:56:22 +0200184elseif s:ext !~ '\.utf-8' && filereadable(s:tutorxx . ".utf-8")
185 " Fallback to utf-8 if available.
186 let $TUTOR = s:tutorxx . ".utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000187else
188 let $TUTOR = $VIMRUNTIME . s:tutorfile
189 echo "The file " . s:tutorxx . " does not exist.\n"
190 echo "Copying English version: " . $TUTOR
191 4sleep
192endif
193
194" 4. Making the copy and exiting Vim:
195e $TUTOR
196wq! $TUTORCOPY