Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim tutor support file |
| 2 | " Author: Eduardo F. Amatria <eferna1@platea.pntic.mec.es> |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 3 | " Maintainer: Bram Moolenaar |
Bram Moolenaar | 42ebd06 | 2016-07-17 13:35:14 +0200 | [diff] [blame^] | 4 | " Last Change: 2016 Jul 16 |
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, |
| 9 | " it defaults to the english version. |
| 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 | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 25 | elseif $LANG =~ '\a\a' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 26 | 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 Moolenaar | 946e27a | 2014-06-25 18:50:27 +0200 | [diff] [blame] | 39 | elseif s:lang =~ "Serbian" |
| 40 | let s:ext = ".sr" |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 41 | elseif s:lang =~ "Czech" |
| 42 | let s:ext = ".cs" |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 43 | elseif s:lang =~ "Dutch" |
| 44 | let s:ext = ".nl" |
Bram Moolenaar | 42ebd06 | 2016-07-17 13:35:14 +0200 | [diff] [blame^] | 45 | elseif s:lang =~ "Bulgarian" |
| 46 | let s:ext = ".bg" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | else |
| 48 | let s:ext = "." . strpart(s:lang, 0, 2) |
| 49 | endif |
| 50 | endif |
| 51 | endif |
| 52 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 53 | " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). |
| 54 | if s:ext =~? '\.ge' |
| 55 | let s:ext = ".de" |
| 56 | endif |
| 57 | |
| 58 | if s:ext =~? '\.en' |
| 59 | let s:ext = "" |
| 60 | endif |
| 61 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 62 | " The japanese tutor is available in two encodings, guess which one to use |
| 63 | " The "sjis" one is actually "cp932", it doesn't matter for this text. |
| 64 | if s:ext =~? '\.ja' |
| 65 | if &enc =~ "euc" |
| 66 | let s:ext = ".ja.euc" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 67 | elseif &enc != "utf-8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 68 | let s:ext = ".ja.sjis" |
| 69 | endif |
| 70 | endif |
| 71 | |
| 72 | " The korean tutor is available in two encodings, guess which one to use |
| 73 | if s:ext =~? '\.ko' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 74 | if &enc != "utf-8" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 75 | let s:ext = ".ko.euc" |
| 76 | endif |
| 77 | endif |
| 78 | |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 79 | " 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] | 80 | " This segment is from the above lines and modified by |
| 81 | " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 82 | " When 'encoding' is utf-8, choose between China (simplified) and Taiwan |
| 83 | " (traditional) based on the language, suggested by Alick Zhao. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 84 | if s:ext =~? '\.zh' |
| 85 | if &enc =~ 'big5\|cp950' |
| 86 | let s:ext = ".zh.big5" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 87 | elseif &enc != 'utf-8' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 88 | let s:ext = ".zh.euc" |
Bram Moolenaar | d09acef | 2012-09-21 14:54:30 +0200 | [diff] [blame] | 89 | 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 93 | endif |
| 94 | endif |
| 95 | |
| 96 | " 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] | 97 | if s:ext =~? '\.pl' |
| 98 | if &enc =~ 1250 |
| 99 | let s:ext = ".pl.cp1250" |
Bram Moolenaar | c0197e2 | 2004-09-13 20:26:32 +0000 | [diff] [blame] | 100 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 101 | endif |
| 102 | |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 103 | " The Turkish tutor is available in two encodings, guess which one to use |
| 104 | if s:ext =~? '\.tr' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 105 | if &enc == "iso-8859-9" |
Bram Moolenaar | a5792f5 | 2005-11-23 21:25:05 +0000 | [diff] [blame] | 106 | let s:ext = ".tr.iso9" |
| 107 | endif |
| 108 | endif |
| 109 | |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 110 | " The Greek tutor is available in three encodings, guess what to use. |
| 111 | " We used ".gr" (Greece) instead of ".el" (Greek); accept both. |
| 112 | if s:ext =~? '\.gr\|\.el' |
| 113 | if &enc == "iso-8859-7" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 114 | let s:ext = ".el" |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 115 | elseif &enc == "utf-8" |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 116 | let s:ext = ".el.utf-8" |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 117 | elseif &enc =~ 737 |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 118 | let s:ext = ".el.cp737" |
Bram Moolenaar | 4512509 | 2006-09-10 11:24:31 +0000 | [diff] [blame] | 119 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 120 | endif |
| 121 | |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 122 | " The Slovak tutor is available in three encodings, guess which one to use |
| 123 | if s:ext =~? '\.sk' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 124 | if &enc =~ 1250 |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 125 | let s:ext = ".sk.cp1250" |
| 126 | endif |
| 127 | endif |
| 128 | |
Bram Moolenaar | 946e27a | 2014-06-25 18:50:27 +0200 | [diff] [blame] | 129 | " 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. |
| 132 | if s:ext =~? '\.sr' |
| 133 | if &enc =~ 1250 |
| 134 | let s:ext = ".sr.cp1250" |
| 135 | endif |
| 136 | endif |
| 137 | |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 138 | " The Czech tutor is available in three encodings, guess which one to use |
| 139 | if s:ext =~? '\.cs' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 140 | if &enc =~ 1250 |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 141 | let s:ext = ".cs.cp1250" |
| 142 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 143 | endif |
| 144 | |
Bram Moolenaar | d9380f5 | 2006-09-02 12:50:52 +0000 | [diff] [blame] | 145 | " The Russian tutor is available in three encodings, guess which one to use. |
| 146 | if s:ext =~? '\.ru' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 147 | if &enc =~ '1251' |
Bram Moolenaar | d9380f5 | 2006-09-02 12:50:52 +0000 | [diff] [blame] | 148 | let s:ext = '.ru.cp1251' |
| 149 | elseif &enc =~ 'koi8' |
| 150 | let s:ext = '.ru' |
| 151 | endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 152 | endif |
| 153 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 154 | " 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] | 155 | if s:ext =~? '\.hu' |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 156 | if &enc =~ 1250 |
| 157 | let s:ext = ".hu.cp1250" |
Bram Moolenaar | d7afed3 | 2007-05-06 13:26:41 +0000 | [diff] [blame] | 158 | elseif &enc =~ 'iso-8859-2' |
| 159 | let s:ext = '.hu' |
| 160 | endif |
| 161 | endif |
| 162 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 163 | " The Croatian tutor is available in three encodings, guess which one to use. |
| 164 | if 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 Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | endif |
| 171 | |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 172 | " Esperanto is only available in utf-8 |
| 173 | if s:ext =~? '\.eo' |
| 174 | let s:ext = ".eo.utf-8" |
| 175 | endif |
| 176 | " Vietnamese is only available in utf-8 |
| 177 | if s:ext =~? '\.vi' |
| 178 | let s:ext = ".vi.utf-8" |
| 179 | endif |
| 180 | |
| 181 | " If 'encoding' is utf-8 s:ext must end in utf-8. |
| 182 | if &enc == 'utf-8' && s:ext !~ '\.utf-8' |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 183 | let s:ext .= '.utf-8' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | endif |
| 185 | |
| 186 | " 2. Build the name of the file: |
| 187 | let s:tutorfile = "/tutor/tutor" |
| 188 | let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext |
| 189 | |
| 190 | " 3. Finding the file: |
| 191 | if filereadable(s:tutorxx) |
| 192 | let $TUTOR = s:tutorxx |
| 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 |