1" Vim tutor support file 2" Author: Eduardo F. Amatria <[email protected]> 3" Maintainer: Bram Moolenaar 4" Last Change: 2014 Jun 25 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 else 46 let s:ext = "." . strpart(s:lang, 0, 2) 47 endif 48 endif 49endif 50 51" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). 52if s:ext =~? '\.ge' 53 let s:ext = ".de" 54endif 55 56if s:ext =~? '\.en' 57 let s:ext = "" 58endif 59 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. 62if s:ext =~? '\.ja' 63 if &enc =~ "euc" 64 let s:ext = ".ja.euc" 65 elseif &enc != "utf-8" 66 let s:ext = ".ja.sjis" 67 endif 68endif 69 70" The korean tutor is available in two encodings, guess which one to use 71if s:ext =~? '\.ko' 72 if &enc != "utf-8" 73 let s:ext = ".ko.euc" 74 endif 75endif 76 77" The Chinese tutor is available in three encodings, guess which one to use 78" This segment is from the above lines and modified by 79" Mendel L Chan <[email protected]> for Chinese vim tutorial 80" When 'encoding' is utf-8, choose between China (simplified) and Taiwan 81" (traditional) based on the language, suggested by Alick Zhao. 82if s:ext =~? '\.zh' 83 if &enc =~ 'big5\|cp950' 84 let s:ext = ".zh.big5" 85 elseif &enc != 'utf-8' 86 let s:ext = ".zh.euc" 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" 91 endif 92endif 93 94" The Polish tutor is available in two encodings, guess which one to use. 95if s:ext =~? '\.pl' 96 if &enc =~ 1250 97 let s:ext = ".pl.cp1250" 98 endif 99endif 100 101" The Turkish tutor is available in two encodings, guess which one to use 102if s:ext =~? '\.tr' 103 if &enc == "iso-8859-9" 104 let s:ext = ".tr.iso9" 105 endif 106endif 107 108" The Greek tutor is available in three encodings, guess what to use. 109" We used ".gr" (Greece) instead of ".el" (Greek); accept both. 110if s:ext =~? '\.gr\|\.el' 111 if &enc == "iso-8859-7" 112 let s:ext = ".el" 113 elseif &enc == "utf-8" 114 let s:ext = ".el.utf-8" 115 elseif &enc =~ 737 116 let s:ext = ".el.cp737" 117 endif 118endif 119 120" The Slovak tutor is available in three encodings, guess which one to use 121if s:ext =~? '\.sk' 122 if &enc =~ 1250 123 let s:ext = ".sk.cp1250" 124 endif 125endif 126 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. 130if s:ext =~? '\.sr' 131 if &enc =~ 1250 132 let s:ext = ".sr.cp1250" 133 endif 134endif 135 136" The Czech tutor is available in three encodings, guess which one to use 137if s:ext =~? '\.cs' 138 if &enc =~ 1250 139 let s:ext = ".cs.cp1250" 140 endif 141endif 142 143" The Russian tutor is available in three encodings, guess which one to use. 144if s:ext =~? '\.ru' 145 if &enc =~ '1251' 146 let s:ext = '.ru.cp1251' 147 elseif &enc =~ 'koi8' 148 let s:ext = '.ru' 149 endif 150endif 151 152" The Hungarian tutor is available in three encodings, guess which one to use. 153if s:ext =~? '\.hu' 154 if &enc =~ 1250 155 let s:ext = ".hu.cp1250" 156 elseif &enc =~ 'iso-8859-2' 157 let s:ext = '.hu' 158 endif 159endif 160 161" The Croatian tutor is available in three encodings, guess which one to use. 162if 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 168endif 169 170" Esperanto is only available in utf-8 171if s:ext =~? '\.eo' 172 let s:ext = ".eo.utf-8" 173endif 174" Vietnamese is only available in utf-8 175if s:ext =~? '\.vi' 176 let s:ext = ".vi.utf-8" 177endif 178 179" If 'encoding' is utf-8 s:ext must end in utf-8. 180if &enc == 'utf-8' && s:ext !~ '\.utf-8' 181 let s:ext .= '.utf-8' 182endif 183 184" 2. Build the name of the file: 185let s:tutorfile = "/tutor/tutor" 186let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext 187 188" 3. Finding the file: 189if filereadable(s:tutorxx) 190 let $TUTOR = s:tutorxx 191else 192 let $TUTOR = $VIMRUNTIME . s:tutorfile 193 echo "The file " . s:tutorxx . " does not exist.\n" 194 echo "Copying English version: " . $TUTOR 195 4sleep 196endif 197 198" 4. Making the copy and exiting Vim: 199e $TUTOR 200wq! $TUTORCOPY 201