Difference between revisions of "Module:Utilities"
From Pathfinder Wiki
DesignerThan (talk | contribs) |
DesignerThan (talk | contribs) |
||
Line 11: | Line 11: | ||
-- called every time ... shouldn't be a time issue needs between 40 and 80 microseconds | -- called every time ... shouldn't be a time issue needs between 40 and 80 microseconds | ||
-- local langSuffix = frame:expandTemplate{ title = 'GetLangSuffix' } | -- local langSuffix = frame:expandTemplate{ title = 'GetLangSuffix' } | ||
− | local langSuffix = frame: | + | local langSuffix = frame:expandTemplate{ title = 'PAGELANGUAGE' } |
mw.log('Utilities.localize (langSuffix): '..langSuffix) | mw.log('Utilities.localize (langSuffix): '..langSuffix) | ||
Line 20: | Line 20: | ||
end | end | ||
− | local strFromTrans = frame:callParserFunction( '#lst', { 'Localization:'..page..langSuffix, strToTrans}) | + | local strFromTrans = frame:callParserFunction( '#lst', { 'Localization:'..page..langSuffix, strToTrans } ) |
-- did translation work? | -- did translation work? | ||
if ( strFromTrans ~= '') then | if ( strFromTrans ~= '') then |
Revision as of 18:38, 17 July 2021
Documentation for this module may be created at Module:Utilities/doc
local p = {}
function p.localize( strToTrans, page )
local frame = mw.getCurrentFrame()
mw.log('Utilities.localize (strToTrans, page - input): '..strToTrans..', '..tostring(page))
if ( page == nil or page == '' ) then
page = 'All'
end
mw.log('Utilities.localize (page - checked): '..page)
-- called every time ... shouldn't be a time issue needs between 40 and 80 microseconds
-- local langSuffix = frame:expandTemplate{ title = 'GetLangSuffix' }
local langSuffix = frame:expandTemplate{ title = 'PAGELANGUAGE' }
mw.log('Utilities.localize (langSuffix): '..langSuffix)
-- check if input is a number
if ( tonumber(strToTrans) ~= nil ) then
mw.log('Utilities.localize: Input String is a number, return it!')
return strToTrans
end
local strFromTrans = frame:callParserFunction( '#lst', { 'Localization:'..page..langSuffix, strToTrans } )
-- did translation work?
if ( strFromTrans ~= '') then
return strFromTrans
else
-- add to error category
-- [[Category:Missing Localization/{{{2|All}}}/{{{1|unsupplied}}}{{GetLangSuffix}}]]
local newErrorCategory = '[[Category:Missing Localization/'..page..'/'..strToTrans..langSuffix..']]'
local errorCategories = frame:callParserFunction( '#var', 'localizationErrorCategories' )
frame:callParserFunction( '#vardefine', { 'localizationErrorCategories', errorCategories..newErrorCategory } )
return strToTrans
end
end
return p