このモジュールについての説明文ページを Module:Technique/doc に作成できます
local p = {}
local linguistic = require('Module:Linguistic')
local synonyms = require('Module:Technique/synonyms')
local declension = require('Module:Declension')
local fallback = require( 'Module:Fallback' )
function notsupportederror(term, sortkey)
local text = mw.text.decode('<red>' .. term .. '</red>')
local errorcat = mw.text.decode( '[[Category:Pages with incorrect template usage/Technique|' .. sortkey .. ']]')
return text .. errorcat
end
function makegroup(noun, adj, langpage, lang, case) -- turn a adj + noun group into a human-readable string
-- I preprocess parameters
if not noun or mw.text.trim(noun) == '' then
return nil
end
if not noun then return "no noun" end
noun = string.lower(mw.text.trim(noun))
if adj and mw.text.trim(adj) ~= '' then
adj = string.lower(mw.text.trim(adj))
else adj = nil
end
if synonyms.nouns[noun] then -- tansform the noun into another one supported by language specific lists
noun = synonyms.nouns[noun]
end
if adj and synonyms.adjectives[adj] then
adj = synonyms.adjectives[adj]
end
-- II error messages
if not langpage.nouns[noun] then
return notsupportederror(noun, "A")
end
if adj and not langpage.adjectives[adj] then
return notsupportederror(adj, "B")
end
---- III process adj (before noun as it needs the original noun
--- IIIa preprocessing
local gender, number, decl = nil, nil, nil -- do not work if they are initialized in an if
if adj then
gender = langpage.nouns[noun]['gender']
if gender == 'm' then gender = 1 end
if gender == 'f' then gender = 2 end
if gender == 'n' then gender = 3 end
number = langpage.nouns[noun]['number']
if not number then number = 's' end
decl = langpage.declension[case]
--- IIIb translation + declension
---- languages with grammatical flexions
if type(langpage.adjectives[adj]) == 'table' then
if langpage.adjectives[adj]['declension'] == 'regular' then
adj = langpage.adjectives[adj]['label']
adj = declension.makeregular(lang, adj, 'adj', number, gender, decl)
elseif langpage.adj[adj]['declension'] then-- irregular adjectives, delensions provdied on the page
adj = langpage.adjectives[adj][number][decl][gender]
else -- languages with gender but no declensions
adj = langpage.adjectives[adj]['label']
end
--- languages with invariable adjectives
elseif type(langpage.adjectives[adj]) == 'string' then -- languages with invariable words
adj = langpage.adjectives[adj]
else
adj = 'something wrong with the datatype of adj:' .. adj
end
end
--- IV process noun
if type(langpage.nouns[noun]) == 'table' then -- complex languages
if langpage.declension[case] then -- with declension
noun = langpage.nouns[noun][langpage.declension[case]]
elseif langpage.nouns[noun]['label'] then -- no declension
noun = langpage.declension[noun]['label']
else
noun = 'error with noun: ' .. noun
end
elseif type(langpage.nouns[noun]) == 'string' then -- language with grammatical flexsions
noun = langpage.nouns[noun]
else
noun = 'error with the datatype of noun: ' .. noun
end
--V finalize
local group = linguistic.noungroup(noun, adj, lang)
return langpage.nomgroup(group, case, gender, case)
end
function findlang(lang) -- return the most approriate subpage for the language
return fallback.fallbackpage('Module:Technique', lang, 'table')
end
function p.technique(frame) -- main function used by the module
local args = frame.args
local lang = args.lang
if not lang then
lang = frame:preprocess( "{{int:lang}}" )
end
-- escape module for special values with separate translation
local test = string.lower(args.noun1.. args.adj1 .. args.noun2 .. args.over .. args.on .. args.adjon .. args.mounted)
if test == 'oilcanvas' then
return fallback.langSwitch(require('Module:I18n/oil on canvas'), lang)
elseif (test == 'oilwood') or (test == 'oilwood') then
return fallback.langSwitch(require('Module:I18n/oil on panel'), lang)
elseif (test == 'unknwown') then
return frame:expandTemplate{ title = 'Temppate:Unknown', args = {'technique'} }
end
-- set language
local l = findlang(lang)
local langpage = require(l[1])
local lang= l[2]
-- group arguments
local group1 = makegroup(args.noun1, args.adj1, langpage, lang, 'default')
local group2 = makegroup(args.noun2, args.adj2, langpage, lang, 'default')
local group3 = makegroup(args.noun3, args.adj3, langpage, lang, 'default')
local group4 = makegroup(args.noun4, args.adj4, langpage, lang, 'default')
local group5 = makegroup(args.noun5, args.adj5, langpage, lang, 'default')
local maingroup = linguistic.conj({group1, group2, group3, group4, group5}, lang) -- technique without "on", "mounted" and "over"
local overgroup = makegroup(args.over, args.adjover, langpage, lang, 'over')
local ongroup = makegroup(args.on, args.adjon, langpage, lang, 'on')
local mountedgroup = makegroup(args.mounted, args.adjmounted, langpage, lang, 'mounted')
if not overgroup then overgroup = '' end -- groups set to '' so they can be concatenated in the /lang page
if not ongroup then ongroup = '' end
if not mountedgroup then mountedgroup = '' end
return langpage.grouporder(maingroup, overgroup, ongroup, mountedgroup)
end
return p