模組:Road data/strings/TWN

-- 臺灣
local TWN = {}
local format = mw.ustring.format
local function en_to_tiangan(num) -- 轉換為天干
	local transfer = {a="甲",b="乙",c="丙",d="丁",e="戊",f="己",g="庚"}
	if (transfer[string.sub(num,-1,-1)]== nil) then 
		return ""
	else
		return transfer[string.sub(num,-1,-1)]
	end
end

---國道---
TWN.Fwy = {shield = {hook = "lowercase",---國道
                     default = "TWHW%lowercase%.svg"},
                   --主線--
           link = {["1"] = "中山高速公路", 
           	       ["2"] = "國道二號 (中華民國)", 
           	       ["3"] = "福爾摩沙高速公路",
           	       ["4"] = "國道四號 (中華民國)", 
           	       ["5"] = "蔣渭水高速公路", 
           	       ["6"] = "水沙連高速公路",
           	       ["7"] = "國道七號 (中華民國)", 
           	       ["8"] = "國道八號 (中華民國)",
                   ["10"] = "國道十號 (中華民國)",
                   --支線--
                   ["1a"] = "桃園航空城北側聯外高速公路", 
                   ["2a"] = "國道二號甲線",
                   ["3a"] = "國道三號甲線"},
                 --主線--         
          abbr = {["1"] = "國道一號", 
          	      ["2"] = "國道二號", 
          	      ["3"] = "國道三號", 
          	      ["4"] = "國道四號", 
          	      ["5"] = "國道五號",
                  ["6"] = "國道六號", 
                  ["7"] = "國道七號", 
                  ["8"] = "國道八號",
                  ["10"] = "國道十號",
                 --支線--
                  ["1a"] = "國道一號甲線", 
                  ["2a"] = "國道二號甲線", 
                  ["3a"] = "國道三號甲線"},
          width = "expand"}

TWN.Freeway = TWN.Fwy
TWN.NH = TWN.Fwy
---(擴充)國道全稱---
TWN["Fwy-ALL"] = {shield = {hook = "lowercase",
                     default = "TWHW%lowercase%.svg"},
                   --主線--
           link = {["1"] = "中山高速公路", 
           	       ["2"] = "國道二號 (中華民國)", 
           	       ["3"] = "福爾摩沙高速公路",
           	       ["4"] = "國道四號 (中華民國)", 
           	       ["5"] = "蔣渭水高速公路", 
           	       ["6"] = "水沙連高速公路",
           	       ["7"] = "高雄港東側聯外高速公路", 
           	       ["8"] = "國道八號 (中華民國)", 
                   ["10"] = "國道十號 (中華民國)",
                   --支線--
                   ["1a"] = "桃園航空城北側聯外高速公路", 
                   ["2a"] = "國道二號甲線", 
                   ["3a"] = "國道三號甲線"},
                 --主線--         
          abbr = {["1"] = "中山高速公路", 
          	      ["2"] = "桃園環線", 
          	      ["3"] = "福爾摩沙高速公路", 
          	      ["4"] = "台中環線", 
          	      ["5"] = "蔣渭水高速公路",
                  ["6"] = "水沙連高速公路", 
                  ["7"] = "高雄港東側聯外高速公路", 
                  ["8"] = "台南支線", 
                  ["10"] = "高雄支線",
                 --支線--
                  ["1a"] = "桃園航空城北側聯外高速公路", 
                  ["2a"] = "大園支線", 
                  ["3a"] = "台北聯絡線"},
          width = "expand"}

TWN["Freeway-ALL"] = TWN["Fwy-ALL"]
TWN["NH-ALL"] = TWN["Fwy-ALL"]

---省道---
local ph_aux_number =  {"1a","1b","1c","1d","1e","1f","2a","2b","2c","2d","2e","2f","2g","3a","3b","3c","5a","5b","7a","7b","7c","7d",
						"8a","9a","9b","9c","9d","9e","10b","11a","11b","11c","13a","14a","14b","14c","14d","15a","17a","17b","19a",
						"20a","20b","21a","27a","61a","61b","62a","63a","68a","74a"}

local ph_link = {default = "台%route%線"}
local ph_abbr = {default = "台%route%線"}

for _, num in ipairs(ph_aux_number) do
	ph_link[num] = format("台%s線#%s線", string.sub(num,1,-2), en_to_tiangan(num))
	ph_abbr[num] = format("台%s%s線", string.sub(num,1,-2), en_to_tiangan(num))
end

TWN.PH = {shield = {hook = "lowercase",
                    default = "TW PHW%lowercase%.svg"},
           link = ph_link,
           abbr = ph_abbr,
	       width = "expand"}

---(擴充)快速公路全稱---
TWN["PH-ALL"] = {shield = {hook = "lowercase",
                     default = "TW PHW%lowercase%.svg"},
           link = {default = "台%route%線", 
                   ["2f"] = "台2線#己線",
                   ["61"] = "西部濱海快速公路", 
                   ["61a"] = "西部濱海快速公路#甲線(已解編)", 
                   ["61b"] = "西部濱海快速公路#乙線",
                   ["62a"] = "台62線#甲線",
                   ["74a"] = "台74線#甲線"},            
           abbr = {["2f"] = "基隆港西岸聯外道路",
                   ["61"] = "西部濱海快速公路", 
                   ["61b"] = "彰濱聯絡道",
           	       ["62"] = "萬里瑞濱線",
           	       ["62a"] = "基隆港東岸聯外道路",
           	       ["63"] = "中投公路",
           	       ["64"] = "八里新店線", 
           	       ["65"] = "五股土城線",
           	       ["66"] = "觀音大溪線", 
           	       ["68"] = "南寮竹東線", 
                   ["72"] = "後龍汶水線",
                   ["74"] = "快官霧峰線", 
                   ["74a"] = "彰化東外環道", 
                   ["76"] = "芳苑草屯線",
                   ["78"] = "台西古坑線",
                   ["82"] = "東石嘉義線",
                   ["84"] = "北門玉井線",
                   ["86"] = "台南關廟線",
                   ["88"] = "高雄潮州線"},
          width = "expand"}

---縣市道---
local cr_number =  {city_main = {"101","102","103","104","105","106","107","108","109","110",
								 "111","112","113","114","115","116","118","121","125","127",
								 "129","132","136","165","171","172","173","174","175","176",
								 "177","178","180","181","182","183","186","188"},
					city_aux = {"101a","102a","103a","106a","107a","110a","112a","113a","114a",
								"132a","171a","172a","173a","177a","178a","180a","183a","186a",
								"106b","110b","113b","171b","172b","183b",
								"113c"},
					county_aux = {"119a","124a","134a","135a","138a","139a","143a","144a","145a","146a","149a",
								  "151a","153a","154a","156a","158a","159a","162a","185a","187a","189a","191a",
								  "192a","196a","199a","200a","204a",
								  "124b","124a","134b","139b","145b","149b","154b","156b","158b","162b","187b",
								  "191b",
								  "124c","187c"}}

local function cr_link_format(types,num)
	local tiangan = en_to_tiangan(num)
	local formats = {city_main = format("市道%s號",num),
				 	 city_aux = format("市道%s號#%s線", string.sub(num,1,-2), tiangan),
					 county_aux = format("縣道%s號#%s線", string.sub(num,1,-2), tiangan)}
	return formats[types]
end

local function cr_abbr_format(types,num)
	local tiangan = en_to_tiangan(num)
	local formats = {city_main = format("市道%s號",num),
				 	 city_aux = format("市道%s%s線", string.sub(num,1,-2), tiangan),
					 county_aux = format("縣道%s%s線", string.sub(num,1,-2), tiangan)}
	return formats[types]
end

local cr_link = {default = "縣道%route%號"}
local cr_abbr = {default = "縣道%route%號"}

for _, types in ipairs({"city_main","city_aux","county_aux"}) do
	for _, num in ipairs(cr_number[types]) do
		cr_link[num] = cr_link_format(types,num)
		cr_abbr[num] = cr_abbr_format(types,num)
	end 
end

TWN.CR = {shield = {hook = "lowercase",
                    default = "TW CHW%lowercase%.svg"},
           link = cr_link,
           abbr = cr_abbr,
	       width = "expand"}

TWN.CH = TWN.CR

---(擴充)只顯示「縣道XXX」---
local cr2_link = {default = "縣道%route%號"}
local cr2_abbr = {default = "縣道%route%號"}

for _, types in ipairs({"city_aux","county_aux"}) do
	for _, num in ipairs(cr_number[types]) do
		cr2_link[num] = cr_link_format(types,num)
		cr2_abbr[num] = format("縣道%s%s線", string.sub(num,1,-2), en_to_tiangan(num))
	end 
end

TWN.CR2 = {shield = {hook = "lowercase",
                    default = "TW CHW%lowercase%.svg"},
           link = cr2_link,
           abbr = cr2_abbr,
	       width = "expand"}

TWN.CH2 = TWN.CR2

---鄉區道---
local county_en = {"TP","TY","HC","ML","TC","CH","NT","YL","CY","TN","KH","PT",
				   "IL","HL","TT","PH"}

local function county_abbr(cname) --轉換為縣市鄉區道簡稱
	local tables = {TP="北",TY="桃",HC="竹",ML="苗",TC="中",CH="彰",NT="投",YL="雲",
					CY="嘉",TN="南",KH="高",PT="屏",IL="宜",HL="花",TT="東",PH="澎"}
	return tables[cname]
end

for _, cname in ipairs(county_en) do
	num = "%route%"
	TWN["TR"..cname] = {shield = format("TW THW%s%s.svg", string.lower(cname), num),
		                link = format("%s%s線", county_abbr(cname), num),
		                abbr = format("%s%s線", county_abbr(cname), num)}
end

return TWN