Mercurial > vim
annotate runtime/tutor/tutor.vim @ 29598:b838b8a9b726
Added tag v9.0.0139 for changeset f2d7f20d83c3939699545fa9fad85bfb65465662
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Aug 2022 16:15:09 +0200 |
parents | c4cdc715cb68 |
children | 71cbad0921c9 |
rev | line source |
---|---|
7 | 1 " Vim tutor support file |
2 " Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es> | |
1698 | 3 " Maintainer: Bram Moolenaar |
18615 | 4 " Last Change: 2019 Nov 11 |
7 | 5 |
1698 | 6 " This Vim script is used for detecting if a translation of the |
7 | 7 " 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, | |
13735 | 9 " it defaults to the English version. |
7 | 10 |
11 " It is invoked by the vimtutor shell script. | |
12 | |
13 " 1. Build the extension of the file, if any: | |
14 let s:ext = "" | |
15 if strlen($xx) > 1 | |
16 let s:ext = "." . $xx | |
17 else | |
18 let s:lang = "" | |
782 | 19 " Check that a potential value has at least two letters. |
20 " Ignore "1043" and "C". | |
21 if exists("v:lang") && v:lang =~ '\a\a' | |
7 | 22 let s:lang = v:lang |
782 | 23 elseif $LC_ALL =~ '\a\a' |
205 | 24 let s:lang = $LC_ALL |
16168
7688bff96a8c
patch 8.1.1089: tutor does not check $LC_MESSAGES
Bram Moolenaar <Bram@vim.org>
parents:
14372
diff
changeset
|
25 elseif $LC_MESSAGES =~ '\a\a' || $LC_MESSAGES ==# "C" |
7688bff96a8c
patch 8.1.1089: tutor does not check $LC_MESSAGES
Bram Moolenaar <Bram@vim.org>
parents:
14372
diff
changeset
|
26 " LC_MESSAGES=C can be used to explicitly ask for English messages while |
7688bff96a8c
patch 8.1.1089: tutor does not check $LC_MESSAGES
Bram Moolenaar <Bram@vim.org>
parents:
14372
diff
changeset
|
27 " keeping LANG non-English; don't set s:lang then. |
7688bff96a8c
patch 8.1.1089: tutor does not check $LC_MESSAGES
Bram Moolenaar <Bram@vim.org>
parents:
14372
diff
changeset
|
28 if $LC_MESSAGES =~ '\a\a' |
7688bff96a8c
patch 8.1.1089: tutor does not check $LC_MESSAGES
Bram Moolenaar <Bram@vim.org>
parents:
14372
diff
changeset
|
29 let s:lang = $LC_MESSAGES |
7688bff96a8c
patch 8.1.1089: tutor does not check $LC_MESSAGES
Bram Moolenaar <Bram@vim.org>
parents:
14372
diff
changeset
|
30 endif |
782 | 31 elseif $LANG =~ '\a\a' |
7 | 32 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" | |
6009 | 45 elseif s:lang =~ "Serbian" |
46 let s:ext = ".sr" | |
1154 | 47 elseif s:lang =~ "Czech" |
48 let s:ext = ".cs" | |
782 | 49 elseif s:lang =~ "Dutch" |
50 let s:ext = ".nl" | |
9555
9560a5b782ee
commit https://github.com/vim/vim/commit/42ebd066422d73cdb7bda6a1dc828a3dd022dec8
Christian Brabandt <cb@256bit.org>
parents:
6009
diff
changeset
|
51 elseif s:lang =~ "Bulgarian" |
9560a5b782ee
commit https://github.com/vim/vim/commit/42ebd066422d73cdb7bda6a1dc828a3dd022dec8
Christian Brabandt <cb@256bit.org>
parents:
6009
diff
changeset
|
52 let s:ext = ".bg" |
7 | 53 else |
54 let s:ext = "." . strpart(s:lang, 0, 2) | |
55 endif | |
56 endif | |
57 endif | |
58 | |
1621 | 59 " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). |
60 if s:ext =~? '\.ge' | |
61 let s:ext = ".de" | |
62 endif | |
63 | |
64 if s:ext =~? '\.en' | |
65 let s:ext = "" | |
66 endif | |
67 | |
14372 | 68 " The Japanese tutor is available in three encodings, guess which one to use |
7 | 69 " The "sjis" one is actually "cp932", it doesn't matter for this text. |
70 if s:ext =~? '\.ja' | |
71 if &enc =~ "euc" | |
72 let s:ext = ".ja.euc" | |
1621 | 73 elseif &enc != "utf-8" |
7 | 74 let s:ext = ".ja.sjis" |
75 endif | |
76 endif | |
77 | |
14372 | 78 " The Korean tutor is available in two encodings, guess which one to use |
7 | 79 if s:ext =~? '\.ko' |
1621 | 80 if &enc != "utf-8" |
7 | 81 let s:ext = ".ko.euc" |
82 endif | |
83 endif | |
84 | |
3830 | 85 " The Chinese tutor is available in three encodings, guess which one to use |
7 | 86 " This segment is from the above lines and modified by |
87 " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial | |
3830 | 88 " When 'encoding' is utf-8, choose between China (simplified) and Taiwan |
89 " (traditional) based on the language, suggested by Alick Zhao. | |
7 | 90 if s:ext =~? '\.zh' |
91 if &enc =~ 'big5\|cp950' | |
92 let s:ext = ".zh.big5" | |
1621 | 93 elseif &enc != 'utf-8' |
7 | 94 let s:ext = ".zh.euc" |
3830 | 95 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" | |
7 | 99 endif |
100 endif | |
101 | |
102 " The Polish tutor is available in two encodings, guess which one to use. | |
24 | 103 if s:ext =~? '\.pl' |
104 if &enc =~ 1250 | |
105 let s:ext = ".pl.cp1250" | |
106 endif | |
7 | 107 endif |
108 | |
557 | 109 " The Turkish tutor is available in two encodings, guess which one to use |
110 if s:ext =~? '\.tr' | |
18615 | 111 if &enc == "iso-8859-9" || &enc == "cp1254" |
557 | 112 let s:ext = ".tr.iso9" |
113 endif | |
114 endif | |
115 | |
969 | 116 " The Greek tutor is available in three encodings, guess what to use. |
117 " We used ".gr" (Greece) instead of ".el" (Greek); accept both. | |
118 if s:ext =~? '\.gr\|\.el' | |
119 if &enc == "iso-8859-7" | |
1621 | 120 let s:ext = ".el" |
969 | 121 elseif &enc == "utf-8" |
1621 | 122 let s:ext = ".el.utf-8" |
969 | 123 elseif &enc =~ 737 |
1621 | 124 let s:ext = ".el.cp737" |
969 | 125 endif |
7 | 126 endif |
127 | |
1154 | 128 " The Slovak tutor is available in three encodings, guess which one to use |
129 if s:ext =~? '\.sk' | |
1621 | 130 if &enc =~ 1250 |
1154 | 131 let s:ext = ".sk.cp1250" |
132 endif | |
133 endif | |
134 | |
6009 | 135 " 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. | |
138 if s:ext =~? '\.sr' | |
139 if &enc =~ 1250 | |
140 let s:ext = ".sr.cp1250" | |
141 endif | |
142 endif | |
143 | |
1154 | 144 " The Czech tutor is available in three encodings, guess which one to use |
145 if s:ext =~? '\.cs' | |
1621 | 146 if &enc =~ 1250 |
1154 | 147 let s:ext = ".cs.cp1250" |
148 endif | |
7 | 149 endif |
150 | |
953 | 151 " The Russian tutor is available in three encodings, guess which one to use. |
152 if s:ext =~? '\.ru' | |
1621 | 153 if &enc =~ '1251' |
953 | 154 let s:ext = '.ru.cp1251' |
155 elseif &enc =~ 'koi8' | |
156 let s:ext = '.ru' | |
157 endif | |
7 | 158 endif |
159 | |
1621 | 160 " The Hungarian tutor is available in three encodings, guess which one to use. |
1154 | 161 if s:ext =~? '\.hu' |
1621 | 162 if &enc =~ 1250 |
163 let s:ext = ".hu.cp1250" | |
1154 | 164 elseif &enc =~ 'iso-8859-2' |
165 let s:ext = '.hu' | |
166 endif | |
167 endif | |
168 | |
1621 | 169 " The Croatian tutor is available in three encodings, guess which one to use. |
170 if 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 | |
7 | 176 endif |
177 | |
1621 | 178 " If 'encoding' is utf-8 s:ext must end in utf-8. |
179 if &enc == 'utf-8' && s:ext !~ '\.utf-8' | |
1698 | 180 let s:ext .= '.utf-8' |
7 | 181 endif |
182 | |
183 " 2. Build the name of the file: | |
184 let s:tutorfile = "/tutor/tutor" | |
185 let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext | |
186 | |
187 " 3. Finding the file: | |
188 if filereadable(s:tutorxx) | |
189 let $TUTOR = s:tutorxx | |
14372 | 190 elseif s:ext !~ '\.utf-8' && filereadable(s:tutorxx . ".utf-8") |
191 " Fallback to utf-8 if available. | |
192 let $TUTOR = s:tutorxx . ".utf-8" | |
7 | 193 else |
194 let $TUTOR = $VIMRUNTIME . s:tutorfile | |
195 echo "The file " . s:tutorxx . " does not exist.\n" | |
196 echo "Copying English version: " . $TUTOR | |
197 4sleep | |
198 endif | |
199 | |
200 " 4. Making the copy and exiting Vim: | |
201 e $TUTOR | |
202 wq! $TUTORCOPY |