پودمان:نام انگلیسی کشور
ظاهر
require('strict')
local p = {}
local yesno = require('Module:Yesno')
local num_convert = require('Module:Numeral converter').convert
local function switch_type(second_param, third_param)
local result = {}
local year_string = second_param and mw.ustring.match(second_param, '%d%d?%d?%d?')
if second_param and type(year_string) == 'string' then
result.year = year_string
if third_param and third_param == 'رسمی' then
result.type = 'formal'
else
result.type = 'common'
end
else
result.year = false
if second_param == 'رسمی' or third_param == 'رسمی' then
result.type = 'formal'
elseif second_param == 'تاریخی' or third_param == 'تاریخی' then
result.type = 'historical'
elseif second_param == 'کوتاه' or third_param == 'کوتاه' then
result.type = 'short'
elseif second_param == 'غیررسمی' or third_param == 'غیررسمی' then
result.type = 'informal'
else
result.type = 'common'
end
end
return result
end
function p.get_data(country, year, variant)
local data, article
local error = false
local data_table = require('پودمان:نام انگلیسی کشور/دادهها')
if country and country ~= '' then
if not data_table[country] then
data = mw.ustring.format(data_table['no data'], country)
error = true
else
article = data_table[country]['article'] or country
if (year and year ~= '' and type(data_table[country][num_convert('en', year)]) == 'table') then
data = data_table[country][num_convert('en', year)][variant] or
(variant == 'historical' and
data_table[country][variant] or
data_table[country]['current'][variant]
)
else
if variant == 'historical' then
data = data_table[country]['historical'] or data_table[country]['current']['commmon']
else
data = data_table[country]['current'][variant] or data_table[country]['current']['common']
end
end
end
else
data = data_table['no input']
error = true
end
return data, error, article
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {valueFunc =
function(key, value)
if value then
value = mw.text.trim(value)
end
return value
end
})
local processed_param_values = switch_type(args[2], args[3])
local result, error, article_title = p.get_data(args[1], processed_param_values.year, processed_param_values.type)
if error then
result = '<span class="error">' .. result .. '</span>'
else
if args['پیوند'] and yesno(args['پیوند']) then
result = '[[' .. article_title .. '|' .. result .. ']]'
end
end
return result
end
return p