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> |
| 3 | " Last Change: 2004 Jun 03 |
| 4 | |
| 5 | " This small source file is used for detecting if a translation of the |
| 6 | " tutor file exist, i.e., a tutor.xx file, where xx is the language. |
| 7 | " If the translation does not exist, or no extension is given, |
| 8 | " it defaults to the english version. |
| 9 | |
| 10 | " It is invoked by the vimtutor shell script. |
| 11 | |
| 12 | " 1. Build the extension of the file, if any: |
| 13 | let s:ext = "" |
| 14 | if strlen($xx) > 1 |
| 15 | let s:ext = "." . $xx |
| 16 | else |
| 17 | let s:lang = "" |
| 18 | if exists("v:lang") && v:lang != "C" |
| 19 | let s:lang = v:lang |
| 20 | elseif strlen($LANG) > 0 && $LANG != "C" |
| 21 | let s:lang = $LANG |
| 22 | endif |
| 23 | if s:lang != "" |
| 24 | " Remove "@euro" (ignoring case), it may be at the end |
| 25 | let s:lang = substitute(s:lang, '\c@euro', '', '') |
| 26 | " On MS-Windows it may be German_Germany.1252 or Polish_Poland.1250. How |
| 27 | " about other languages? |
| 28 | if s:lang =~ "German" |
| 29 | let s:ext = ".de" |
| 30 | elseif s:lang =~ "Polish" |
| 31 | let s:ext = ".pl" |
| 32 | elseif s:lang =~ "Slovak" |
| 33 | let s:ext = ".sk" |
| 34 | else |
| 35 | let s:ext = "." . strpart(s:lang, 0, 2) |
| 36 | endif |
| 37 | endif |
| 38 | endif |
| 39 | |
| 40 | " The japanese tutor is available in two encodings, guess which one to use |
| 41 | " The "sjis" one is actually "cp932", it doesn't matter for this text. |
| 42 | if s:ext =~? '\.ja' |
| 43 | if &enc =~ "euc" |
| 44 | let s:ext = ".ja.euc" |
| 45 | elseif &enc =~ "utf-8$" |
| 46 | let s:ext = ".ja.utf-8" |
| 47 | else |
| 48 | let s:ext = ".ja.sjis" |
| 49 | endif |
| 50 | endif |
| 51 | |
| 52 | " The korean tutor is available in two encodings, guess which one to use |
| 53 | if s:ext =~? '\.ko' |
| 54 | if &enc =~ "utf-8$" |
| 55 | let s:ext = ".ko.utf-8" |
| 56 | else |
| 57 | let s:ext = ".ko.euc" |
| 58 | endif |
| 59 | endif |
| 60 | |
| 61 | " The Chinese tutor is available in two encodings, guess which one to use |
| 62 | " This segment is from the above lines and modified by |
| 63 | " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial |
| 64 | if s:ext =~? '\.zh' |
| 65 | if &enc =~ 'big5\|cp950' |
| 66 | let s:ext = ".zh.big5" |
| 67 | else |
| 68 | let s:ext = ".zh.euc" |
| 69 | endif |
| 70 | endif |
| 71 | |
| 72 | " The Polish tutor is available in two encodings, guess which one to use. |
| 73 | if s:ext =~? '\.pl' && &enc =~ 1250 |
| 74 | let s:ext = ".pl.cp1250" |
| 75 | endif |
| 76 | |
| 77 | " The Greek tutor is available in two encodings, guess which one to use |
| 78 | if s:ext =~? '\.gr' && &enc =~ 737 |
| 79 | let s:ext = ".gr.cp737" |
| 80 | endif |
| 81 | |
| 82 | " The Slovak tutor is available in two encodings, guess which one to use |
| 83 | if s:ext =~? '\.sk' && &enc =~ 1250 |
| 84 | let s:ext = ".sk.cp1250" |
| 85 | endif |
| 86 | |
| 87 | " The Russian tutor is available in two encodings, guess which one to use. |
| 88 | " This segment is from the above lines and modified by |
| 89 | " Alexey I. Froloff <raorn@altlinux.org> for Russian vim tutorial |
| 90 | if s:ext =~? '\.ru' && &enc =~ 1251 |
| 91 | let s:ext = ".ru.cp1251" |
| 92 | endif |
| 93 | |
| 94 | " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). |
| 95 | if s:ext =~? '\.ge' |
| 96 | let s:ext = ".de" |
| 97 | endif |
| 98 | |
| 99 | if s:ext =~? '\.en' |
| 100 | let s:ext = "" |
| 101 | endif |
| 102 | |
| 103 | " 2. Build the name of the file: |
| 104 | let s:tutorfile = "/tutor/tutor" |
| 105 | let s:tutorxx = $VIMRUNTIME . s:tutorfile . s:ext |
| 106 | |
| 107 | " 3. Finding the file: |
| 108 | if filereadable(s:tutorxx) |
| 109 | let $TUTOR = s:tutorxx |
| 110 | else |
| 111 | let $TUTOR = $VIMRUNTIME . s:tutorfile |
| 112 | echo "The file " . s:tutorxx . " does not exist.\n" |
| 113 | echo "Copying English version: " . $TUTOR |
| 114 | 4sleep |
| 115 | endif |
| 116 | |
| 117 | " 4. Making the copy and exiting Vim: |
| 118 | e $TUTOR |
| 119 | wq! $TUTORCOPY |