Module:In lang/sandbox: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 131:
--[[--------------------------< N I H O N G O _ R E N D E R E R >----------------------------------------------
 
shared support function for nihingo(), nihongo3(), and nihongo3nihongo_foot(). does finalCalculates assemblyan andindex into renderingformatting{}
from set/unset parameters:
args[1] (english) has a value of 8 (set) or 0 (unset)
args[2] (japanese) has a value of 4
args[3] (romaji) has a value of 2
args[4] (extra) has a value of 1
index, the sum of these values, gets the appropriate format string from formatting{} table with associated values
from the formatting[index][2] table
 
]]
Line 140 ⟶ 147:
local param_weight = {8, 4, 2, 1}; -- binary parameter weights: [1] = english (8), [2] = japanese (4), [3] = romaji (2), [4] = extra (1)
 
for i=1, 5 do -- calculatespin anthrough indexargs[1] into formatting{}args[4]
index = index + (args[i] and param_weight[i] or 0); -- calculate an index into formatting{}
end
 
output = (0 ~= index) and string.format (formatting[index][1] and formatting[index][1], formatting[index][2][1], formatting[index][2][2], formatting[index][2][3], formatting[index][2][4]) or nil;
 
if extra2 then
if extra2 then -- always just attached to the end (if there is an end) so not part of formatting{}
output = output and (output .. ' ' .. extra2) or '<span style="font-weight: normal">' .. extra2;
output = output and (output .. ' ' .. extra2) or '<5p4n>' .. extra2; -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, to be replaced
end
end -- (nihongo and nihongo3) or removed (nihongo foot)
 
return output .. '</span>';
return output and (output .. '</5p4n>') or ''; -- where there is output, add secret tag close
end
 
Line 188 ⟶ 196:
end
local formatting = { -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, replaced before function returns
local span = '<span style="font-weight: normal">'; -- to bold only the first english, japanese, or romaji when template used in definition list (; markup)
{'<5p4n>(%s)', {extra}}, -- 1 - (extra)
{'%s<5p4n>', {romaji}}, -- 2 - romaji
local formatting = {
{'%s<span style="font-weight: normal"5p4n> (%s)', {romaji, extra}}, -- 13 - romaji (extra)
{'<5p4n>(%s<span style="font-weight: normal">)', {romaji, spanjapanese}}, -- 24 - romajijapanese
{'%s<span style="font-weight: normal"5p4n> (%s, %s)', {romajijapanese, extra}}, -- 35 - romaji (japanese, extra)
{'%s<span style="font-weight: normal"5p4n> (%s)', {romaji, japanese}}, -- 46 - romaji (japanese)
{'%s<span5p4n> style="font-weight: normal">(%s, %s)', {romaji, japanese, extra}}, -- 57 - romaji (japanese, extra)
{'%s<span style="font-weight: normal"5p4n> (%s)', {romaji, japaneseenglish}}, -- 68 - romaji (japanese)english
{'%s<span style="font-weight: normal"5p4n> (%s, %s)', {romaji, japaneseenglish, extra}}, -- 79 - romajienglish (japanese, extra)
{'%s<span5p4n> style="font-weight: normal">(%s)', {english, spanromaji}}, -- 810 - english (romaji)
{'%s<span style="font-weight: normal"5p4n> (%s, %s)', {english, romaji, extra}}, -- 911 - english (romaji, extra)
{'%s<span style="font-weight: normal"5p4n> (%s)', {english, romajijapanese}}, -- 1012 - english (romajijapanese)
{'%s<span style="font-weight: normal"5p4n> (%s, %s)', {english, romajijapanese, extra}}, -- 1113 - english (romajijapanese, extra)
{'%s<span style="font-weight: normal"5p4n> (%s, %s)', {english, japanese, romaji}}, -- 1214 - english (japanese, romaji)
{'%s<span style="font-weight: normal"5p4n> (%s, %s, %s)', {english, japanese, romaji, extra}}, -- 1315 - english (japanese, romaji, extra)
{'%s<span style="font-weight: normal"> (%s, %s)', {english, japanese, romaji}}, -- 14 - english (japanese, romaji)
{'%s<span style="font-weight: normal"> (%s, %s, %s)', {english, japanese, romaji, extra}}, -- 15 - english (japanese, romaji, extra)
}
 
returnlocal ret_string = nihongo_renderer (args, formatting, extra2);
ret_string = ret_string:gsub ('<5p4n>', '<span style="font-weight: normal">'):gsub ('</5p4n>', '</span>'); -- replace 'secret' tags with proper tags
return ret_string;
end
 
Line 243 ⟶ 251:
romaji = romaji and lang_module._transl ({'ja', 'hepburn', romaji}) or nil;
local formatting = { -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, replaced before function returns
local formatting = {
{'<5p4n>(%s)', {extra}}, -- 1 - (extra)
{'%s<5p4n>', {romaji}}, -- 2 - romaji
{'%s<5p4n> (%s)', {romaji, extra}}, -- 3 - romaji (extra)
{'<5p4n>(%s)', {japanese}}, -- 4 - japanese
{'<5p4n>(%s, %s)', {japanese, extra}}, -- 5 - (japanese, extra)
{'%s<5p4n> (%s)', {romaji, japanese}}, -- 6 - romaji (japanese)
{'%s<5p4n> (%s, %s)', {romaji, japanese, extra}}, -- 7 - romaji (japanese, extra)
{'%s<5p4n>', {english}}, -- 8 - english
{'%s<5p4n> (%s)', {english, extra}}, -- 9 - english (extra)
{'%s<5p4n> (%s)', {romaji, english}}, -- 10 - romaji (english)
{'%s<5p4n> (%s, %s)', {romaji, english, extra}}, -- 11 - romaji (english, extra)
{'%s<5p4n> (%s)', {english, japanese}}, -- 12 - english (japanese)
{'%s<5p4n> (%s, %s)', {english, japanese, extra}}, -- 13 - english (japanese, extra)
{'%s<5p4n> (%s, %s)', {romaji, japanese, english}}, -- 14 - romaji (japanese, english)
{'%s<5p4n> (%s, %s, %s)', {romaji, japanese, english, extra}}, -- 15 - romaji (japanese, english, extra)
}
 
returnlocal ret_string = nihongo_renderer (args, formatting, extra2);
ret_string = ret_string:gsub ('<5p4n>', '<span style="font-weight: normal">'):gsub ('</5p4n>', '</span>'); -- replace 'secret' tags with proper tags
return ret_string; -- because gsub returns the number of replacements mad as second return value
end
 
Line 334 ⟶ 344:
 
if japanese or romaji or extra or extra2 then -- no ref tag when none of these are set (it would be empty)
returnlocal englishcontent .. frame:extensionTag ({name='ref', args={group=group}, content=nihongo_renderer (args, formatting, extra2)});
content = content:gsub ('<5p4n>', ''):gsub ('</5p4n>$', '', 1); -- strip secret <5p4n> and </5p4n> tags added by nihongo_renderer(); spans not used by this template
 
return english .. frame:extensionTag ({name='ref', args={group=group}, content=content}); -- english with attached reference tag
else
return english; -- nothing to be inside ref tag so just return english
return;
end
end