Module:China Expwy Name

-----------------------------------------------------------------------

-- Module:China Expwy Name - Lua module for China Expwy Name template

-----------------------------------------------------------------------

-- For the code-name convensions

-----------------------------------------------------------------------

-- 模組：China Expwy Name - 中國 Expwy Name 模板的 Lua 模組

-----------------------------------------------------------------------

-- 對於代號約定

local p =

-- Icon width for different code, according to GB5768-2009

-- 不同程式碼的圖示寬度，根據 GB5768-2009

local width_translation = {

1 = "22px",

2 = "27px",

3 = "32px",

4 = "37px"

}

-- Language code for different ethnics

-- 不同種族的語言程式碼

local lang_codes = {

"維" = "ug", "維" = "ug", "ug" = "ug",

"藏" = "bo", "bo" = "bo",

"蒙" = "mn", "mn" = "mn"

}

-- Province library

-- 庫圖書館

local province_lib = mw.loadData ("Module:China Expwy Name/Province")

-- Main expressway code-name translation library

-- 主要高速公路代號翻譯庫

local expwy_lib = mw.loadData ("Module:China Expwy Name/NameFromCode")

local image_refs = mw.loadData ("Module:China Expwy Name/ImageRefs")

-- Code translation against ambiguity, such as G1501s

-- 防止歧義的程式碼翻譯，例如 G1501

local code_translation = mw.loadData ("Module:China Expwy Name/TranslateCode")

--

function trim (s)

return s:match "^% s(.-)% s$"

end

--

function clean_tags (s)

return string.gsub (string.gsub (trim (s), , ), "'", "")

end

--

function internal_translatecode (province, id)

if codetranslationprovince == nil or codetranslationprovinceid == nil then

return id

else

return code_translationprovinceid

end

end

-- Functionality for code-name conversion

-- 代號轉換功能

function p.fullname (frame)

if frame.args1 == nil then

return "error"

else

id = clean_tags (string.upper (frame.args1))

end

if frame.args2 == nil then

province = "CHINA"

else

province = trim (string.upper (frame.args2))

end

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

if expwy_libprovince == nil then

return "error"

elseif expwy_libprovinceid == nil then

return "error"

else

return expwy_libprovinceid

end

end

-- Functionality for raw code fetching (e.g., G1501SH -> G1501)

-- 原始程式碼提取的功能（例如，G1501SH-> G1501）

function p.translatecode (frame)

if frame.args1 == nil then

return ""

else

id = clean_tags (string.upper (frame.args1))

end

if frame.args2 == nil then

province = "CHINA"

else

province = trim (string.upper (frame.args2))

end

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

return internal_translatecode (province, id)

end

function internalimagelink (frame, typ, link)

if frame.args1 == nil then

return ""

else

id = clean_tags (string.upper (frame.args1))

end

if frame.args2 == nil or trim (frame.args2) == then

province = "CHINA"

else

province = trim (string.upper (frame.args2))

end

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

truecode = internaltranslatecode (province, id)

truecodelen = string.len (true_code) - 1

if frame.args3 ~= nil and string.upper (frame.args3) ~= "D" then

image_width = frame.args3

else

if widthtranslationtruecode_len == nil then

return ""

else

imagewidth = widthtranslationtruecodelen

end

end

imagerefexists = false

if typ == 0 then -- sign no name

baseimagename = provincelib.dbprovince.imageprefix .. "Expwy" .. true_code .. "sign no name"

if imagerefsprovince ~= nil and imagerefsprovincetruecode ~= nil and imagerefsprovincetruecode.noname ~= nil then

imagerefexists = imagerefsprovincetruecode.no_name

end

else -- sign with name

baseimagename = provincelib.dbprovince.imageprefix .. "Expwy" .. id .. "sign with name"

if imagerefsprovince ~= nil and imagerefsprovinceid ~= nil and imagerefsprovinceid.withname ~= nil then

imagerefexists = imagerefsprovinceid.withname

end

if frame.args4 ~= nil then

langcode = langcodestrim (string.lower (frame.args4))

if lang_code ~= nil then

imagerefexists = false

baseimagename = baseimagename .. ' ' .. lang_code

if imagerefsprovince ~= nil and imagerefsprovinceid ~= nil and imagerefsprovinceid.langs ~= nil and imagerefsprovinceid.langslang_code ~= nil then

imagerefexists = imagerefsprovinceid.langslangcode

end

end

end

end

if not imagerefexists then

svgtitle = mw.title.makeTitle ("File", baseimage_name .. '.svg')

imagerefexists = svg_title.fileExists

end

if imagerefexists then

if link == nil then

return

else

return

end

else

return ""

end

end

-- Functionality for sign width fetching

-- 標誌寬度獲取功能

function p.imagenoname (frame)

return internalimagelink (frame, 0, nil)

end

-- Functionality for sign width fetching

-- 標誌寬度獲取功能

function p.imagewithname (frame)

return internalimagelink (frame, 1, nil)

end

function p.imagelinkwith_name (frame)

return internalimagelink (frame, 1, p.fullname (frame))

end

function p.imagelinkno_name (frame)

return internalimagelink (frame, 0, p.fullname (frame))

end

-- Functionality for sign width fetching

-- 標誌寬度獲取功能

function p.signwidth (frame)

if frame.args1 == nil then

return width_translation1

else

id = clean_tags (string.upper (frame.args1))

end

if frame.args2 == nil then

province = "CHINA"

else

province = trim (string.upper (frame.args2))

end

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

truecodelen = string.len (internal_translatecode (province, id)) - 1

if widthtranslationtruecode_len == nil then

return width_translation1

else

return widthtranslationtruecode_len

end

end

function p.provinceshortname (frame)

if frame.args1 == nil then

return ""

end

province = trim (string.upper (frame.args1))

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

if province_lib.dbprovince == nil then

return ""

end

return provincelib.dbprovince.shortname

end

function p.provincelongname (frame)

if frame.args1 == nil then

return ""

end

province = trim (string.upper (frame.args1))

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

if province_lib.dbprovince == nil then

return ""

end

return provincelib.dbprovince.longname

end

function p.provincehighwaylink (frame)

if frame.args1 == nil then

return ""

end

province = trim (string.upper (frame.args1))

if provincelib.chnlibprovince ~= nil then

province = provincelib.chnlibprovince

end

if province_lib.dbprovince == nil then

return ""

end

return .. provincelib.dbprovince.expwylink ..

end

function p.enumerateroadids (frame)

out_str =

for province, pset in pairs (expwy_lib) do

for roadid, roadname in pairs (pset) do

truecode = internaltranslatecode (province, road_id)

roadstr = province .. '|' .. provincelib.dbprovince.imageprefix .. '|' .. roadid .. '|' .. true_code

if out_str == then

outstr = roadstr

else

outstr = outstr .. ';' .. road_str

end

end

end

return out_str

end

return p