Difference between revisions of "Module:HonorUtils"
From Pathfinder Wiki
DesignerThan (talk | contribs) |
DesignerThan (talk | contribs) |
||
Line 2: | Line 2: | ||
local strUtils = require( "Module:StringUtils" ) | local strUtils = require( "Module:StringUtils" ) | ||
− | function p.getCompletExpandedHonorVariants(variantsString, landingPage, langSuffix) | + | function p.getCompletExpandedHonorVariants(frame, variantsString, landingPage, langSuffix) |
− | local t_variants = p.expandHonorVariants(variantsString) | + | local t_variants = p.expandHonorVariants(frame, variantsString) |
− | t_variants = p.translateHonorVariants(t_variants) | + | t_variants = p.translateHonorVariants(frame, t_variants) |
− | t_variants = p.createHonorVariantsURLs(t_variants, landingPage, targetPage, langSuffix) | + | t_variants = p.createHonorVariantsURLs(frame, t_variants, landingPage, targetPage, langSuffix) |
end | end | ||
− | function p.honorVariantsExpand(variantsString) | + | function p.honorVariantsExpand(frame, variantsString) |
--[[structure of variants String: | --[[structure of variants String: | ||
variant1;;authority1:authority2::counry1;counry2;country3;;variant3 | variant1;;authority1:authority2::counry1;counry2;country3;;variant3 | ||
Line 28: | Line 28: | ||
end | end | ||
− | function p.translateHonorVariants(variants) | + | function p.translateHonorVariants(frame, variants) |
local t_variants = variants | local t_variants = variants | ||
for varKey, variant in pairs(variants) do | for varKey, variant in pairs(variants) do | ||
Line 43: | Line 43: | ||
end | end | ||
− | function p.createHonorVariantsURLs(variants, landingPage, targetPage, langSuffix) | + | function p.createHonorVariantsURLs(frame, variants, landingPage, targetPage, langSuffix) |
local t_variants = variants | local t_variants = variants | ||
for key, variant in pairs(variants) do | for key, variant in pairs(variants) do |
Revision as of 19:25, 27 June 2021
Documentation for this module may be created at Module:HonorUtils/doc
local p = {}
local strUtils = require( "Module:StringUtils" )
function p.getCompletExpandedHonorVariants(frame, variantsString, landingPage, langSuffix)
local t_variants = p.expandHonorVariants(frame, variantsString)
t_variants = p.translateHonorVariants(frame, t_variants)
t_variants = p.createHonorVariantsURLs(frame, t_variants, landingPage, targetPage, langSuffix)
end
function p.honorVariantsExpand(frame, variantsString)
--[[structure of variants String:
variant1;;authority1:authority2::counry1;counry2;country3;;variant3
NAD::United States;;NAD(EUD;SPD)::Austria;Switzerland;Germany
NAD;;NAD(EUD)
]]
if (variantsString == nil or variantsString == "") then return {} end
local t_variants = strUtils.explode(";;", variantsString)
for key, variant in pairs(t_variants) do
t_variants[key] = {
orig = variant,
countries = strUtils.explode(";", variant)
}
end
return t_variants
end
function p.translateHonorVariants(frame, variants)
local t_variants = variants
for varKey, variant in pairs(variants) do
for countryKey, country in pairs(variant['countries']) do
local trans = frame:expandTemplate{ title = 'Localize', args = { subVariant, 'Answer Variants' } }
local t_countryTrans = {
orig = country,
translation = trans
}
t_variants[key]['countries'][countryKey] = t_countryTrans
end
end
return t_variants
end
function p.createHonorVariantsURLs(frame, variants, landingPage, targetPage, langSuffix)
local t_variants = variants
for key, variant in pairs(variants) do
local linkTitle = ""
for countryKey, country in pairs(variant['countries']) do
if (#linkTitle > 0) then
linkTitle = linkTitle .. " & " .. country['translation']
else
linkTitle = country['translation']
end
end
t_variants[key]['url'] ="[[" .. landingPage .. "_(" .. variant['orig'] .. ")/" .. targetPage .. langSuffix .. "|" .. linkTitle .. "]]"
end
return t_variants
end
return p