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