blob: 809fd1d126752c74b9a3c92423a48aede9be8800 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim tutor support file
Christian Brabandte8d6f032023-08-23 20:23:07 +01002" Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es>
3" Maintainer: The·Vim·Project·<https://github.com/vim/vim>
4" Last Change: 2023 Aug 13
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 Moolenaarb44b7ad2019-03-30 19:56:46 +010025 elseif $LC_MESSAGES =~ '\a\a' || $LC_MESSAGES ==# "C"
26 " LC_MESSAGES=C can be used to explicitly ask for English messages while
27 " keeping LANG non-English; don't set s:lang then.
28 if $LC_MESSAGES =~ '\a\a'
29 let s:lang = $LC_MESSAGES
30 endif
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000031 elseif $LANG =~ '\a\a'
Bram Moolenaar071d4272004-06-13 20:20:40 +000032 let s:lang = $LANG
33 endif
34 if s:lang != ""
35 " Remove "@euro" (ignoring case), it may be at the end
36 let s:lang = substitute(s:lang, '\c@euro', '', '')
37 " On MS-Windows it may be German_Germany.1252 or Polish_Poland.1250. How
38 " about other languages?
39 if s:lang =~ "German"
40 let s:ext = ".de"
41 elseif s:lang =~ "Polish"
42 let s:ext = ".pl"
43 elseif s:lang =~ "Slovak"
44 let s:ext = ".sk"
Bram Moolenaar946e27a2014-06-25 18:50:27 +020045 elseif s:lang =~ "Serbian"
46 let s:ext = ".sr"
Bram Moolenaard7afed32007-05-06 13:26:41 +000047 elseif s:lang =~ "Czech"
48 let s:ext = ".cs"
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000049 elseif s:lang =~ "Dutch"
50 let s:ext = ".nl"
Bram Moolenaar42ebd062016-07-17 13:35:14 +020051 elseif s:lang =~ "Bulgarian"
52 let s:ext = ".bg"
Bram Moolenaar071d4272004-06-13 20:20:40 +000053 else
54 let s:ext = "." . strpart(s:lang, 0, 2)
55 endif
56 endif
57endif
58
Bram Moolenaar446cb832008-06-24 21:56:24 +000059" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch).
60if s:ext =~? '\.ge'
61 let s:ext = ".de"
62endif
63
64if s:ext =~? '\.en'
65 let s:ext = ""
66endif
67
Bram Moolenaara9604e62018-07-21 05:56:22 +020068" The Japanese tutor is available in three encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000069" The "sjis" one is actually "cp932", it doesn't matter for this text.
70if s:ext =~? '\.ja'
71 if &enc =~ "euc"
72 let s:ext = ".ja.euc"
Bram Moolenaar446cb832008-06-24 21:56:24 +000073 elseif &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000074 let s:ext = ".ja.sjis"
75 endif
76endif
77
Bram Moolenaara9604e62018-07-21 05:56:22 +020078" The Korean tutor is available in two encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000079if s:ext =~? '\.ko'
Bram Moolenaar446cb832008-06-24 21:56:24 +000080 if &enc != "utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +000081 let s:ext = ".ko.euc"
82 endif
83endif
84
Bram Moolenaard09acef2012-09-21 14:54:30 +020085" The Chinese tutor is available in three encodings, guess which one to use
Bram Moolenaar071d4272004-06-13 20:20:40 +000086" This segment is from the above lines and modified by
87" Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial
Bram Moolenaard09acef2012-09-21 14:54:30 +020088" When 'encoding' is utf-8, choose between China (simplified) and Taiwan
89" (traditional) based on the language, suggested by Alick Zhao.
Bram Moolenaar071d4272004-06-13 20:20:40 +000090if s:ext =~? '\.zh'
91 if &enc =~ 'big5\|cp950'
92 let s:ext = ".zh.big5"
Bram Moolenaar446cb832008-06-24 21:56:24 +000093 elseif &enc != 'utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +000094 let s:ext = ".zh.euc"
Bram Moolenaard09acef2012-09-21 14:54:30 +020095 elseif s:ext =~? 'zh_tw' || (exists("s:lang") && s:lang =~? 'zh_tw')
96 let s:ext = ".zh_tw"
97 else
98 let s:ext = ".zh_cn"
Bram Moolenaar071d4272004-06-13 20:20:40 +000099 endif
100endif
101
102" The Polish tutor is available in two encodings, guess which one to use.
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000103if s:ext =~? '\.pl'
104 if &enc =~ 1250
105 let s:ext = ".pl.cp1250"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000106 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000107endif
108
Bram Moolenaara5792f52005-11-23 21:25:05 +0000109" The Turkish tutor is available in two encodings, guess which one to use
110if s:ext =~? '\.tr'
Bram Moolenaar574ee7b2019-11-13 23:04:29 +0100111 if &enc == "iso-8859-9" || &enc == "cp1254"
Bram Moolenaara5792f52005-11-23 21:25:05 +0000112 let s:ext = ".tr.iso9"
113 endif
114endif
115
Bram Moolenaar45125092006-09-10 11:24:31 +0000116" The Greek tutor is available in three encodings, guess what to use.
117" We used ".gr" (Greece) instead of ".el" (Greek); accept both.
118if s:ext =~? '\.gr\|\.el'
119 if &enc == "iso-8859-7"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000120 let s:ext = ".el"
Bram Moolenaar45125092006-09-10 11:24:31 +0000121 elseif &enc == "utf-8"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000122 let s:ext = ".el.utf-8"
Bram Moolenaar45125092006-09-10 11:24:31 +0000123 elseif &enc =~ 737
Bram Moolenaar446cb832008-06-24 21:56:24 +0000124 let s:ext = ".el.cp737"
Bram Moolenaar45125092006-09-10 11:24:31 +0000125 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000126endif
127
Bram Moolenaard7afed32007-05-06 13:26:41 +0000128" The Slovak tutor is available in three encodings, guess which one to use
129if s:ext =~? '\.sk'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000130 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000131 let s:ext = ".sk.cp1250"
132 endif
133endif
134
Bram Moolenaar946e27a2014-06-25 18:50:27 +0200135" The Slovak tutor is available in two encodings, guess which one to use
136" Note that the utf-8 version is the original, the cp1250 version is created
137" from it.
138if s:ext =~? '\.sr'
139 if &enc =~ 1250
140 let s:ext = ".sr.cp1250"
141 endif
142endif
143
Bram Moolenaard7afed32007-05-06 13:26:41 +0000144" The Czech tutor is available in three encodings, guess which one to use
145if s:ext =~? '\.cs'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000146 if &enc =~ 1250
Bram Moolenaard7afed32007-05-06 13:26:41 +0000147 let s:ext = ".cs.cp1250"
148 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149endif
150
Bram Moolenaard9380f52006-09-02 12:50:52 +0000151" The Russian tutor is available in three encodings, guess which one to use.
152if s:ext =~? '\.ru'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000153 if &enc =~ '1251'
Bram Moolenaard9380f52006-09-02 12:50:52 +0000154 let s:ext = '.ru.cp1251'
155 elseif &enc =~ 'koi8'
156 let s:ext = '.ru'
157 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000158endif
159
Bram Moolenaar446cb832008-06-24 21:56:24 +0000160" The Hungarian tutor is available in three encodings, guess which one to use.
Bram Moolenaard7afed32007-05-06 13:26:41 +0000161if s:ext =~? '\.hu'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000162 if &enc =~ 1250
163 let s:ext = ".hu.cp1250"
Bram Moolenaard7afed32007-05-06 13:26:41 +0000164 elseif &enc =~ 'iso-8859-2'
165 let s:ext = '.hu'
166 endif
167endif
168
Bram Moolenaar446cb832008-06-24 21:56:24 +0000169" The Croatian tutor is available in three encodings, guess which one to use.
170if s:ext =~? '\.hr'
171 if &enc =~ 1250
172 let s:ext = ".hr.cp1250"
173 elseif &enc =~ 'iso-8859-2'
174 let s:ext = '.hr'
175 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176endif
177
Bram Moolenaar446cb832008-06-24 21:56:24 +0000178" If 'encoding' is utf-8 s:ext must end in utf-8.
179if &enc == 'utf-8' && s:ext !~ '\.utf-8'
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000180 let s:ext .= '.utf-8'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000181endif
182
183" 2. Build the name of the file:
184let s:tutorfile = "/tutor/tutor"
185let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext
186
187" 3. Finding the file:
188if filereadable(s:tutorxx)
189 let $TUTOR = s:tutorxx
Bram Moolenaara9604e62018-07-21 05:56:22 +0200190elseif s:ext !~ '\.utf-8' && filereadable(s:tutorxx . ".utf-8")
191 " Fallback to utf-8 if available.
192 let $TUTOR = s:tutorxx . ".utf-8"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193else
194 let $TUTOR = $VIMRUNTIME . s:tutorfile
195 echo "The file " . s:tutorxx . " does not exist.\n"
196 echo "Copying English version: " . $TUTOR
197 4sleep
198endif
199
200" 4. Making the copy and exiting Vim:
201e $TUTOR
202wq! $TUTORCOPY