1" Vim tutor support file 2" Author: Eduardo F. Amatria <[email protected]> 3" Maintainer: Bram Moolenaar 4" Last Change: 2019 Nov 11 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 $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 31 elseif $LANG =~ '\a\a' 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" 45 elseif s:lang =~ "Serbian" 46 let s:ext = ".sr" 47 elseif s:lang =~ "Czech" 48 let s:ext = ".cs" 49 elseif s:lang =~ "Dutch" 50 let s:ext = ".nl" 51 elseif s:lang =~ "Bulgarian" 52 let s:ext = ".bg" 53 else 54 let s:ext = "." . strpart(s:lang, 0, 2) 55 endif 56 endif 57endif 58 59" Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). 60if s:ext =~? '\.ge' 61 let s:ext = ".de" 62endif 63 64if s:ext =~? '\.en' 65 let s:ext = "" 66endif 67 68" The Japanese tutor is available in three encodings, guess which one to use 69" The "sjis" one is actually "cp932", it doesn't matter for this text. 70if s:ext =~? '\.ja' 71 if &enc =~ "euc" 72 let s:ext = ".ja.euc" 73 elseif &enc != "utf-8" 74 let s:ext = ".ja.sjis" 75 endif 76endif 77 78" The Korean tutor is available in two encodings, guess which one to use 79if s:ext =~? '\.ko' 80 if &enc != "utf-8" 81 let s:ext = ".ko.euc" 82 endif 83endif 84 85" The Chinese tutor is available in three encodings, guess which one to use 86" This segment is from the above lines and modified by 87" Mendel L Chan <[email protected]> for Chinese vim tutorial 88" When 'encoding' is utf-8, choose between China (simplified) and Taiwan 89" (traditional) based on the language, suggested by Alick Zhao. 90if s:ext =~? '\.zh' 91 if &enc =~ 'big5\|cp950' 92 let s:ext = ".zh.big5" 93 elseif &enc != 'utf-8' 94 let s:ext = ".zh.euc" 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" 99 endif 100endif 101 102" The Polish tutor is available in two encodings, guess which one to use. 103if s:ext =~? '\.pl' 104 if &enc =~ 1250 105 let s:ext = ".pl.cp1250" 106 endif 107endif 108 109" The Turkish tutor is available in two encodings, guess which one to use 110if s:ext =~? '\.tr' 111 if &enc == "iso-8859-9" || &enc == "cp1254" 112 let s:ext = ".tr.iso9" 113 endif 114endif 115 116" The Greek tutor is available in three encodings, guess what to use. 117" We used ".gr" (Greece) instead of ".el" (Greek); accept both. 118if s:ext =~? '\.gr\|\.el' 119 if &enc == "iso-8859-7" 120 let s:ext = ".el" 121 elseif &enc == "utf-8" 122 let s:ext = ".el.utf-8" 123 elseif &enc =~ 737 124 let s:ext = ".el.cp737" 125 endif 126endif 127 128" The Slovak tutor is available in three encodings, guess which one to use 129if s:ext =~? '\.sk' 130 if &enc =~ 1250 131 let s:ext = ".sk.cp1250" 132 endif 133endif 134 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. 138if s:ext =~? '\.sr' 139 if &enc =~ 1250 140 let s:ext = ".sr.cp1250" 141 endif 142endif 143 144" The Czech tutor is available in three encodings, guess which one to use 145if s:ext =~? '\.cs' 146 if &enc =~ 1250 147 let s:ext = ".cs.cp1250" 148 endif 149endif 150 151" The Russian tutor is available in three encodings, guess which one to use. 152if s:ext =~? '\.ru' 153 if &enc =~ '1251' 154 let s:ext = '.ru.cp1251' 155 elseif &enc =~ 'koi8' 156 let s:ext = '.ru' 157 endif 158endif 159 160" The Hungarian tutor is available in three encodings, guess which one to use. 161if s:ext =~? '\.hu' 162 if &enc =~ 1250 163 let s:ext = ".hu.cp1250" 164 elseif &enc =~ 'iso-8859-2' 165 let s:ext = '.hu' 166 endif 167endif 168 169" The Croatian tutor is available in three encodings, guess which one to use. 170if 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 176endif 177 178" If 'encoding' is utf-8 s:ext must end in utf-8. 179if &enc == 'utf-8' && s:ext !~ '\.utf-8' 180 let s:ext .= '.utf-8' 181endif 182 183" 2. Build the name of the file: 184let s:tutorfile = "/tutor/tutor" 185let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext 186 187" 3. Finding the file: 188if filereadable(s:tutorxx) 189 let $TUTOR = s:tutorxx 190elseif s:ext !~ '\.utf-8' && filereadable(s:tutorxx . ".utf-8") 191 " Fallback to utf-8 if available. 192 let $TUTOR = s:tutorxx . ".utf-8" 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