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
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 --
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 -- always just attached to the end (if there is an end) so not part of formatting{}
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 -- (nihongo and nihongo3) or removed (nihongo foot)
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
{'<5p4n>(%s)', {extra}}, -- 1 - (extra)
{'%s<5p4n>', {romaji}}, -- 2 - romaji
{'%s<
{'<5p4n>(%s
{'
{'%s<
{'%s<
{'%s<
{'%s<
{'%s<
{'%s<
{'%s<
{'%s<
{'%s<
{'%s<
}
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
{'<5p4n>(%s)', {extra}},
{'%s<5p4n>', {romaji}},
{'%s<5p4n> (%s)', {romaji, extra}},
{'<5p4n>(%s)', {japanese}},
{'<5p4n>(%s, %s)', {japanese, extra}},
{'%s<5p4n> (%s)', {romaji, japanese}},
{'%s<5p4n> (%s, %s)', {romaji, japanese, extra}},
{'%s<5p4n>', {english}},
{'%s<5p4n> (%s)', {english, extra}},
{'%s<5p4n> (%s)', {romaji, english}},
{'%s<5p4n> (%s, %s)', {romaji, english, extra}},
{'%s<5p4n> (%s)', {english, japanese}},
{'%s<5p4n> (%s, %s)', {english, japanese, extra}},
{'%s<5p4n> (%s, %s)', {romaji, japanese, english}},
{'%s<5p4n> (%s, %s, %s)', {romaji, japanese, english, extra}},
}
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)
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
end
end
|