| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Vim tutor support file | 
					
						
							| 
									
										
										
										
											2023-08-23 20:23:07 +01:00
										 |  |  | " Author:	Eduardo F. Amatria <eferna1@platea.pntic.mec.es> | 
					
						
							|  |  |  | " Maintainer:	The·Vim·Project·<https://github.com/vim/vim> | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  | " Last Change:	2024 Nov 17 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-06 17:06:04 +00:00
										 |  |  | " This Vim script is used for detecting if a translation of the | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " tutor file exist, i.e., a tutor.xx file, where xx is the language. | 
					
						
							|  |  |  | " If the translation does not exist, or no extension is given, | 
					
						
							| 
									
										
										
										
											2018-04-20 22:36:41 +02:00
										 |  |  | " it defaults to the English version. | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " It is invoked by the vimtutor shell script. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " 1. Build the extension of the file, if any: | 
					
						
							|  |  |  | let s:ext = "" | 
					
						
							|  |  |  | if strlen($xx) > 1 | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  |   let s:ext = "." .. $xx | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | else | 
					
						
							|  |  |  |   let s:lang = "" | 
					
						
							| 
									
										
										
										
											2006-03-18 21:40:56 +00:00
										 |  |  |   " Check that a potential value has at least two letters. | 
					
						
							|  |  |  |   " Ignore "1043" and "C". | 
					
						
							|  |  |  |   if exists("v:lang") && v:lang =~ '\a\a' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     let s:lang = v:lang | 
					
						
							| 
									
										
										
										
											2006-03-18 21:40:56 +00:00
										 |  |  |   elseif $LC_ALL =~ '\a\a' | 
					
						
							| 
									
										
										
										
											2005-03-15 22:43:58 +00:00
										 |  |  |     let s:lang = $LC_ALL | 
					
						
							| 
									
										
										
										
											2019-03-30 19:56:46 +01:00
										 |  |  |   elseif $LC_MESSAGES =~ '\a\a' || $LC_MESSAGES ==# "C" | 
					
						
							|  |  |  |     " LC_MESSAGES=C can be used to explicitly ask for English messages while | 
					
						
							|  |  |  |     " keeping LANG non-English; don't set s:lang then. | 
					
						
							|  |  |  |     if $LC_MESSAGES =~ '\a\a' | 
					
						
							|  |  |  |       let s:lang = $LC_MESSAGES | 
					
						
							|  |  |  |     endif | 
					
						
							| 
									
										
										
										
											2006-03-18 21:40:56 +00:00
										 |  |  |   elseif $LANG =~ '\a\a' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     let s:lang = $LANG | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if s:lang != "" | 
					
						
							|  |  |  |     " Remove "@euro" (ignoring case), it may be at the end | 
					
						
							|  |  |  |     let s:lang = substitute(s:lang, '\c@euro', '', '') | 
					
						
							|  |  |  |     " On MS-Windows it may be German_Germany.1252 or Polish_Poland.1250.  How | 
					
						
							|  |  |  |     " about other languages? | 
					
						
							|  |  |  |     if s:lang =~ "German" | 
					
						
							|  |  |  |       let s:ext = ".de" | 
					
						
							|  |  |  |     elseif s:lang =~ "Polish" | 
					
						
							|  |  |  |       let s:ext = ".pl" | 
					
						
							|  |  |  |     elseif s:lang =~ "Slovak" | 
					
						
							|  |  |  |       let s:ext = ".sk" | 
					
						
							| 
									
										
										
										
											2014-06-25 18:50:27 +02:00
										 |  |  |     elseif s:lang =~ "Serbian" | 
					
						
							|  |  |  |       let s:ext = ".sr" | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  |     elseif s:lang =~ "Czech" | 
					
						
							|  |  |  |       let s:ext = ".cs" | 
					
						
							| 
									
										
										
										
											2006-03-18 21:40:56 +00:00
										 |  |  |     elseif s:lang =~ "Dutch" | 
					
						
							|  |  |  |       let s:ext = ".nl" | 
					
						
							| 
									
										
										
										
											2016-07-17 13:35:14 +02:00
										 |  |  |     elseif s:lang =~ "Bulgarian" | 
					
						
							|  |  |  |       let s:ext = ".bg" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  |       let s:ext = "." .. strpart(s:lang, 0, 2) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     endif | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  | " Somehow ".ge" (Germany) is sometimes used for ".de" (Deutsch). | 
					
						
							|  |  |  | if s:ext =~? '\.ge' | 
					
						
							|  |  |  |   let s:ext = ".de" | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if s:ext =~? '\.en' | 
					
						
							|  |  |  |   let s:ext = "" | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 05:56:22 +02:00
										 |  |  | " The Japanese tutor is available in three encodings, guess which one to use | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " The "sjis" one is actually "cp932", it doesn't matter for this text. | 
					
						
							|  |  |  | if s:ext =~? '\.ja' | 
					
						
							|  |  |  |   if &enc =~ "euc" | 
					
						
							|  |  |  |     let s:ext = ".ja.euc" | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   elseif &enc != "utf-8" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     let s:ext = ".ja.sjis" | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-21 05:56:22 +02:00
										 |  |  | " The Korean tutor is available in two encodings, guess which one to use | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | if s:ext =~? '\.ko' | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   if &enc != "utf-8" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     let s:ext = ".ko.euc" | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-21 14:54:30 +02:00
										 |  |  | " The Chinese tutor is available in three encodings, guess which one to use | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " This segment is from the above lines and modified by | 
					
						
							|  |  |  | " Mendel L Chan <beos@turbolinux.com.cn> for Chinese vim tutorial | 
					
						
							| 
									
										
										
										
											2012-09-21 14:54:30 +02:00
										 |  |  | " When 'encoding' is utf-8, choose between China (simplified) and Taiwan | 
					
						
							|  |  |  | " (traditional) based on the language, suggested by Alick Zhao. | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | if s:ext =~? '\.zh' | 
					
						
							|  |  |  |   if &enc =~ 'big5\|cp950' | 
					
						
							|  |  |  |     let s:ext = ".zh.big5" | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   elseif &enc != 'utf-8' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |     let s:ext = ".zh.euc" | 
					
						
							| 
									
										
										
										
											2012-09-21 14:54:30 +02:00
										 |  |  |   elseif s:ext =~? 'zh_tw' || (exists("s:lang") && s:lang =~? 'zh_tw') | 
					
						
							|  |  |  |     let s:ext = ".zh_tw" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     let s:ext = ".zh_cn" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " The Polish tutor is available in two encodings, guess which one to use. | 
					
						
							| 
									
										
										
										
											2004-09-13 20:26:32 +00:00
										 |  |  | if s:ext =~? '\.pl' | 
					
						
							|  |  |  |   if &enc =~ 1250 | 
					
						
							|  |  |  |     let s:ext = ".pl.cp1250" | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | " The Turkish tutor is available in two encodings, guess which one to use | 
					
						
							|  |  |  | if s:ext =~? '\.tr' | 
					
						
							| 
									
										
										
										
											2019-11-13 23:04:29 +01:00
										 |  |  |   if &enc == "iso-8859-9" || &enc == "cp1254" | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |     let s:ext = ".tr.iso9" | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-10 11:24:31 +00:00
										 |  |  | " The Greek tutor is available in three encodings, guess what to use. | 
					
						
							|  |  |  | " We used ".gr" (Greece) instead of ".el" (Greek); accept both. | 
					
						
							|  |  |  | if s:ext =~? '\.gr\|\.el' | 
					
						
							|  |  |  |   if &enc == "iso-8859-7" | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |     let s:ext = ".el" | 
					
						
							| 
									
										
										
										
											2006-09-10 11:24:31 +00:00
										 |  |  |   elseif &enc == "utf-8" | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |     let s:ext = ".el.utf-8" | 
					
						
							| 
									
										
										
										
											2006-09-10 11:24:31 +00:00
										 |  |  |   elseif &enc =~ 737 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |     let s:ext = ".el.cp737" | 
					
						
							| 
									
										
										
										
											2006-09-10 11:24:31 +00:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  | " The Slovak tutor is available in three encodings, guess which one to use | 
					
						
							|  |  |  | if s:ext =~? '\.sk' | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   if &enc =~ 1250 | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  |     let s:ext = ".sk.cp1250" | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-31 15:20:03 +01:00
										 |  |  | " The Serbian tutor is available in two encodings, guess which one to use | 
					
						
							| 
									
										
										
										
											2014-06-25 18:50:27 +02:00
										 |  |  | " Note that the utf-8 version is the original, the cp1250 version is created | 
					
						
							|  |  |  | " from it. | 
					
						
							|  |  |  | if s:ext =~? '\.sr' | 
					
						
							|  |  |  |   if &enc =~ 1250 | 
					
						
							|  |  |  |     let s:ext = ".sr.cp1250" | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  | " The Czech tutor is available in three encodings, guess which one to use | 
					
						
							|  |  |  | if s:ext =~? '\.cs' | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   if &enc =~ 1250 | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  |     let s:ext = ".cs.cp1250" | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-02 12:50:52 +00:00
										 |  |  | " The Russian tutor is available in three encodings, guess which one to use. | 
					
						
							|  |  |  | if s:ext =~? '\.ru' | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   if &enc =~ '1251' | 
					
						
							| 
									
										
										
										
											2006-09-02 12:50:52 +00:00
										 |  |  |     let s:ext = '.ru.cp1251' | 
					
						
							|  |  |  |   elseif &enc =~ 'koi8' | 
					
						
							|  |  |  |     let s:ext = '.ru' | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  | " The Hungarian tutor is available in three encodings, guess which one to use. | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  | if s:ext =~? '\.hu' | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   if &enc =~ 1250 | 
					
						
							|  |  |  |     let s:ext = ".hu.cp1250" | 
					
						
							| 
									
										
										
										
											2007-05-06 13:26:41 +00:00
										 |  |  |   elseif &enc =~ 'iso-8859-2' | 
					
						
							|  |  |  |     let s:ext = '.hu' | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  | " The Croatian tutor is available in three encodings, guess which one to use. | 
					
						
							|  |  |  | if s:ext =~? '\.hr' | 
					
						
							|  |  |  |   if &enc =~ 1250 | 
					
						
							|  |  |  |     let s:ext = ".hr.cp1250" | 
					
						
							|  |  |  |   elseif &enc =~ 'iso-8859-2' | 
					
						
							|  |  |  |     let s:ext = '.hr' | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  | " If 'encoding' is utf-8 s:ext must end in utf-8. | 
					
						
							|  |  |  | if &enc == 'utf-8' && s:ext !~ '\.utf-8' | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  |   let s:ext ..= '.utf-8' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-03 20:47:53 +01:00
										 |  |  | " 2. Build the name of the file and chapter | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  | let s:chapter = exists("$CHAPTER") ? $CHAPTER : 1 | 
					
						
							| 
									
										
										
										
											2024-11-03 20:47:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  | let s:tutorfile = "/tutor/tutor" .. s:chapter | 
					
						
							|  |  |  | let s:tutorxx = $VIMRUNTIME .. s:tutorfile .. s:ext | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " 3. Finding the file: | 
					
						
							|  |  |  | if filereadable(s:tutorxx) | 
					
						
							|  |  |  |   let $TUTOR = s:tutorxx | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  | elseif s:ext !~ '\.utf-8' && filereadable(s:tutorxx .. ".utf-8") | 
					
						
							| 
									
										
										
										
											2018-07-21 05:56:22 +02:00
										 |  |  |   " Fallback to utf-8 if available. | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  |   let $TUTOR = s:tutorxx .. ".utf-8" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2024-12-02 20:19:52 +01:00
										 |  |  |   let $TUTOR = $VIMRUNTIME .. s:tutorfile | 
					
						
							|  |  |  |   echo "The file " .. s:tutorxx .. " does not exist.\n" | 
					
						
							|  |  |  |   echo "Copying English version: " .. $TUTOR | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   4sleep | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " 4. Making the copy and exiting Vim: | 
					
						
							|  |  |  | e $TUTOR | 
					
						
							|  |  |  | wq! $TUTORCOPY |