Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim tutor support file |
Christian Brabandt | e8d6f03 | 2023-08-23 20:23:07 +0100 | [diff] [blame] | 2 | " 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 6 | " This Vim script is used for detecting if a translation of the |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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, |
Bram Moolenaar | 7dda86f | 2018-04-20 22:36:41 +0200 | [diff] [blame] | 9 | " it defaults to the English version. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 = "" |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 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' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 22 | let s:lang = v:lang |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 23 | elseif $LC_ALL =~ '\a\a' |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 24 | let s:lang = $LC_ALL |
Bram Moolenaar | b44b7ad | 2019-03-30 19:56:46 +0100 | [diff] [blame] | 25 | 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 Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 31 | elseif $LANG =~ '\a\a' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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" |
Bram Moolenaar | 946e27a | 2014-06-25 18:50:27 +0200 | [diff] [blame] | 45 | elseif s:lang =~ "Serbian" |
| 46 | let s:ext = ".sr" |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 47 | elseif s:lang =~ "Czech" |
| 48 | let s:ext = ".cs" |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 49 | elseif s:lang =~ "Dutch" |
| 50 | let s:ext = ".nl" |
Bram Moolenaar | 42ebd06 | 2016-07-17 13:35:14 +0200 | [diff] [blame] | 51 | elseif s:lang =~ "Bulgarian" |
| 52 | let s:ext = ".bg" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 53 | else |
| 54 | let s:ext = "." . strpart(s:lang, 0, 2) |
| 55 | endif |
| 56 | endif |
| 57 | endif |
| 58 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | a9604e6 | 2018-07-21 05:56:22 +0200 | [diff] [blame] | 68 | " The Japanese tutor is available in three encodings, guess which one to use |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 73 | elseif &enc != "utf-8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | let s:ext = ".ja.sjis" |
| 75 | endif |
| 76 | endif |
| 77 | |
Bram Moolenaar | a9604e6 | 2018-07-21 05:56:22 +0200 | [diff] [blame] | 78 | " The Korean tutor is available in two encodings, guess which one to use |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | if s:ext =~? '\.ko' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 80 | if &enc != "utf-8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 81 | let s:ext = ".ko.euc" |
| 82 | endif |
| 83 | endif |
| 84 | |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 85 | " The Chinese tutor is available in three encodings, guess which one to use |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 86 | " This segment is from the above lines and modified by |
| 87 | " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 88 | " When 'encoding' is utf-8, choose between China (simplified) and Taiwan |
| 89 | " (traditional) based on the language, suggested by Alick Zhao. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 90 | if s:ext =~? '\.zh' |
| 91 | if &enc =~ 'big5\|cp950' |
| 92 | let s:ext = ".zh.big5" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 93 | elseif &enc != 'utf-8' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 94 | let s:ext = ".zh.euc" |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 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" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 99 | endif |
| 100 | endif |
| 101 | |
| 102 | " The Polish tutor is available in two encodings, guess which one to use. |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 103 | if s:ext =~? '\.pl' |
| 104 | if &enc =~ 1250 |
| 105 | let s:ext = ".pl.cp1250" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 106 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | endif |
| 108 | |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 109 | " The Turkish tutor is available in two encodings, guess which one to use |
| 110 | if s:ext =~? '\.tr' |
Bram Moolenaar | 574ee7b | 2019-11-13 23:04:29 +0100 | [diff] [blame] | 111 | if &enc == "iso-8859-9" || &enc == "cp1254" |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 112 | let s:ext = ".tr.iso9" |
| 113 | endif |
| 114 | endif |
| 115 | |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 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" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 120 | let s:ext = ".el" |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 121 | elseif &enc == "utf-8" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 122 | let s:ext = ".el.utf-8" |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 123 | elseif &enc =~ 737 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 124 | let s:ext = ".el.cp737" |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 125 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | endif |
| 127 | |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 128 | " The Slovak tutor is available in three encodings, guess which one to use |
| 129 | if s:ext =~? '\.sk' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 130 | if &enc =~ 1250 |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 131 | let s:ext = ".sk.cp1250" |
| 132 | endif |
| 133 | endif |
| 134 | |
Bram Moolenaar | 946e27a | 2014-06-25 18:50:27 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 144 | " The Czech tutor is available in three encodings, guess which one to use |
| 145 | if s:ext =~? '\.cs' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 146 | if &enc =~ 1250 |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 147 | let s:ext = ".cs.cp1250" |
| 148 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 149 | endif |
| 150 | |
Bram Moolenaar | d9380f5 | 2006-09-02 12:50:52 +0000 | [diff] [blame] | 151 | " The Russian tutor is available in three encodings, guess which one to use. |
| 152 | if s:ext =~? '\.ru' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 153 | if &enc =~ '1251' |
Bram Moolenaar | d9380f5 | 2006-09-02 12:50:52 +0000 | [diff] [blame] | 154 | let s:ext = '.ru.cp1251' |
| 155 | elseif &enc =~ 'koi8' |
| 156 | let s:ext = '.ru' |
| 157 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 158 | endif |
| 159 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 160 | " The Hungarian tutor is available in three encodings, guess which one to use. |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 161 | if s:ext =~? '\.hu' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 162 | if &enc =~ 1250 |
| 163 | let s:ext = ".hu.cp1250" |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 164 | elseif &enc =~ 'iso-8859-2' |
| 165 | let s:ext = '.hu' |
| 166 | endif |
| 167 | endif |
| 168 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 176 | endif |
| 177 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 178 | " If 'encoding' is utf-8 s:ext must end in utf-8. |
| 179 | if &enc == 'utf-8' && s:ext !~ '\.utf-8' |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 180 | let s:ext .= '.utf-8' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | a9604e6 | 2018-07-21 05:56:22 +0200 | [diff] [blame] | 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" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |