Database changes have finished applying - please report any issues you're (still) seeing to support@shoutwiki.com.

Moduuli:Aurebesh

Jedipediasta, vapaasta Tähtien sota-tietosanakirjasta tänään, 18. kesäkuuta 2025
Siirry navigaatioonSiirry hakuun

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:Aurebesh/ohje

  1 local p = {}
  2  
  3 local data = mw.loadData('Moduuli:Aurebesh/data')
  4  
  5 local yesno = require('Moduuli:Yesno')
  6  
  7 local imagelink = '[[Tiedosto:%s|link=%s|alt=%s]]'
  8  
  9 local function makeCategoryLink(cat)
 10     -- "Category" is split out here so that the module isn't put into the
 11     -- category "%s" when the page is saved.
 12     return string.format('[[%s:%s]]', 'Luokka', cat)
 13 end
 14  
 15 local function makeWikitextError(msg)
 16     return string.format(
 17         '<strong class="error">Aurebesh-virhe: %s.</strong>%s',
 18         msg,
 19         makeCategoryLink('Sivut, joissa on virheellisiä aurebesh-mallineita')
 20     )
 21 end
 22  
 23 local function escapePattern(str)
 24     return mw.ustring.gsub(str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1")
 25 end
 26  
 27 local function singlechars(args)
 28     local style = args.style
 29     local link = args.link or ''
 30     local ret = {}
 31     for _, arg in ipairs(args) do
 32         char = mw.ustring.lower(arg)
 33         if data.chars[char] then
 34             ret[#ret + 1] = imagelink:format(
 35                 data.chars[char][style],
 36                 link,
 37                 ''
 38             )
 39         else
 40             return makeWikitextError(string.format(
 41                 'tunnistamaton merkki "%s"',
 42                 char
 43             ))
 44         end
 45     end
 46     local spacer = imagelink:format('1pixelspace.png', link, '')
 47     return table.concat(ret, spacer)
 48 end
 49  
 50 function p._main(args)
 51     local style = args.style
 52     if not style then
 53         style = 'regular'
 54     end
 55     if not data.sets.style[style] then
 56         return makeWikitextError('invalid argument to "style"')
 57     end
 58     local digraphs = args.digraphs
 59     if digraphs then
 60         digraphs = yesno(digraphs, 'error')
 61         if digraphs == 'error' then
 62             return makeWikitextError('invalid argument to "digraphs"')
 63         end
 64     else
 65         digraphs = true
 66     end
 67     local link = args.link or ''
 68     local ret = {}
 69     for _, arg in ipairs(args) do
 70         local pos = 0
 71         while pos < mw.ustring.len(arg) do
 72             pos = pos + 1
 73             local char = mw.ustring.sub(arg, pos, pos)
 74             local lookup = mw.ustring.lower(char)
 75             if char == "'" or char == '"' then
 76                 local prevpos = pos - 1
 77                 if prevpos == 0 then
 78                     lookup = char .. 'l'
 79                 else
 80                     local prevchar = mw.ustring.sub(arg, prevpos, prevpos)
 81                     if prevchar == ' ' or prevchar == '\n' or prevchar == '' then
 82                         lookup = char .. 'l'
 83                     else
 84                         lookup = char .. 'r'
 85                     end
 86                 end
 87             end
 88             if digraphs and data.sets.digraphstarts[char] then
 89                 local nextchar = mw.ustring.sub(arg, pos + 1, pos + 1)
 90                 if data.sets.digraphs[char..nextchar] then
 91                     char = char .. nextchar
 92                     lookup = mw.ustring.lower(char)
 93                     pos = pos + 1
 94                 end
 95             end
 96             if char == ' ' or char == '\n' then
 97                 ret[#ret + 1] = char
 98             elseif data.chars[lookup] then
 99                 ret[#ret + 1] = imagelink:format(
100                     data.chars[lookup][style],
101                     link,
102                     char
103                 )
104             else
105                 return makeWikitextError(string.format(
106                     'tunnistamaton merkki "%s"',
107                     char
108                 ))
109             end
110         end
111     end
112     local spacer = imagelink:format('1pixelspace.png', link, '')
113     output = table.concat(ret, spacer)
114     output = mw.ustring.gsub(output, '\n' .. escapePattern(spacer), '\n')
115     return output
116 end
117  
118 local function processArgs(frame)
119     local args = {}
120     for k, v in pairs(frame:getParent().args) do
121         v = v:match('^%s*(.-)%s*$') -- trim whitespace
122         if v ~= '' then
123             args[k] = v
124         end
125     end
126     return args
127 end
128  
129 -- called from deprecated [[Template:Aur]]
130 function p.regular(frame)
131     local args = processArgs(frame)
132     args.style = 'regular'
133     return singlechars(args)
134 end
135  
136 -- called from deprecated [[Template:AurB]]
137 function p.bold(frame)
138     local args = processArgs(frame)
139     args.style = 'bold'
140     return singlechars(args)
141 end
142  
143 -- called from new [[Template:AurText]]
144 function p.main(frame)
145     local args = processArgs(frame)
146     return p._main(args)
147 end
148  
149 return p