1" Vim tutor support file 2" Author: Eduardo F. Amatria <[email protected]> 3" Maintainer: Bram Moolenaar 4" Last Change: 2016 Jul 16 5 6" This Vim script is used for detecting if a translation of the 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: 14let s:ext = "" 15if strlen($xx) > 1 16 let s:ext = "." . $xx 17else 18 let s:lang = "" 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' 22 let s:lang = v:lang 23 elseif $LC_ALL =~ '\a\a' 24 let s:lang = $LC_ALL 25 elseif $LANG =~ '\a\a' 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" 39 elseif s:lang =~ "Serbian" 40 let s:ext = ".sr" 41 elseif s:lang =~ "Czech" 42 let s:ext = ".cs" 43 elseif s:lang =~ "Dutch" 44 let s:ext = ".nl" 45 elseif s:lang =~ "Bulgarian" 46 let s:ext = ".bg" 47 else 48 let s:ext = "." . strpart(s:lang, 0, 2) 49 endif 50 endif 51endif 52 53" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). 54if s:ext =~? '\.ge' 55 let s:ext = ".de" 56endif 57 58if s:ext =~? '\.en' 59 let s:ext = "" 60endif 61 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. 64if s:ext =~? '\.ja' 65 if &enc =~ "euc" 66 let s:ext = ".ja.euc" 67 elseif &enc != "utf-8" 68 let s:ext = ".ja.sjis" 69 endif 70endif 71 72" The korean tutor is available in two encodings, guess which one to use 73if s:ext =~? '\.ko' 74 if &enc != "utf-8" 75 let s:ext = ".ko.euc" 76 endif 77endif 78 79" The Chinese tutor is available in three encodings, guess which one to use 80" This segment is from the above lines and modified by 81" Mendel L Chan <[email protected]> for Chinese vim tutorial 82" When 'encoding' is utf-8, choose between China (simplified) and Taiwan 83" (traditional) based on the language, suggested by Alick Zhao. 84if s:ext =~? '\.zh' 85 if &enc =~ 'big5\|cp950' 86 let s:ext = ".zh.big5" 87 elseif &enc != 'utf-8' 88 let s:ext = ".zh.euc" 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" 93 endif 94endif 95 96" The Polish tutor is available in two encodings, guess which one to use. 97if s:ext =~? '\.pl' 98 if &enc =~ 1250 99 let s:ext = ".pl.cp1250" 100 endif 101endif 102 103" The Turkish tutor is available in two encodings, guess which one to use 104if s:ext =~? '\.tr' 105 if &enc == "iso-8859-9" 106 let s:ext = ".tr.iso9" 107 endif 108endif 109 110" The Greek tutor is available in three encodings, guess what to use. 111" We used ".gr" (Greece) instead of ".el" (Greek); accept both. 112if s:ext =~? '\.gr\|\.el' 113 if &enc == "iso-8859-7" 114 let s:ext = ".el" 115 elseif &enc == "utf-8" 116 let s:ext = ".el.utf-8" 117 elseif &enc =~ 737 118 let s:ext = ".el.cp737" 119 endif 120endif 121 122" The Slovak tutor is available in three encodings, guess which one to use 123if s:ext =~? '\.sk' 124 if &enc =~ 1250 125 let s:ext = ".sk.cp1250" 126 endif 127endif 128 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. 132if s:ext =~? '\.sr' 133 if &enc =~ 1250 134 let s:ext = ".sr.cp1250" 135 endif 136endif 137 138" The Czech tutor is available in three encodings, guess which one to use 139if s:ext =~? '\.cs' 140 if &enc =~ 1250 141 let s:ext = ".cs.cp1250" 142 endif 143endif 144 145" The Russian tutor is available in three encodings, guess which one to use. 146if s:ext =~? '\.ru' 147 if &enc =~ '1251' 148 let s:ext = '.ru.cp1251' 149 elseif &enc =~ 'koi8' 150 let s:ext = '.ru' 151 endif 152endif 153 154" The Hungarian tutor is available in three encodings, guess which one to use. 155if s:ext =~? '\.hu' 156 if &enc =~ 1250 157 let s:ext = ".hu.cp1250" 158 elseif &enc =~ 'iso-8859-2' 159 let s:ext = '.hu' 160 endif 161endif 162 163" The Croatian tutor is available in three encodings, guess which one to use. 164if 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 170endif 171 172" Esperanto is only available in utf-8 173if s:ext =~? '\.eo' 174 let s:ext = ".eo.utf-8" 175endif 176" Vietnamese is only available in utf-8 177if s:ext =~? '\.vi' 178 let s:ext = ".vi.utf-8" 179endif 180 181" If 'encoding' is utf-8 s:ext must end in utf-8. 182if &enc == 'utf-8' && s:ext !~ '\.utf-8' 183 let s:ext .= '.utf-8' 184endif 185 186" 2. Build the name of the file: 187let s:tutorfile = "/tutor/tutor" 188let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext 189 190" 3. Finding the file: 191if filereadable(s:tutorxx) 192 let $TUTOR = s:tutorxx 193else 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 203