Content deleted Content added
m spacing tweaks for some romaji characters Tag: Reverted |
sync from sandbox; Tag: Reverted |
||
Line 49:
return output and (output .. '</5p4n>') or ''; -- where there is output, add secret tag close
end
--[[--------------------------< R O M A J I _ K E R N >--------------------------------------------------------
add kerning when first or last character of romaji contacts adjacent opening or closing paranthesis
In this example, without kerning, the romaji characters 'j' and 'V' are italicized so will contact the parentheses
(<i lang=\"ja-Latn\" title=\"Hepburn transliteration\">jV</i>)
<ret_string> is the formatted template output (except that the magic string '<5p4n>' has not yet been replaced)
<romaji> is the return from lang_module._transl() so is not wrapped in parentheses
]]
local function romaji_kern (ret_string, romaji)
if not romaji or ('' == romaji) then -- if romaji not set
return ret_string; -- then we're done
end
romaji = romaji:gsub ('([%(%)%.%%%+%-%*%?%[%^%$%]])', '%%%1'); -- escape lua pattern characters
local romaji_has_leading_paren = ret_string:match ('%(' .. romaji); -- has a value if (<romaji>; nil else
local romaji_has_trailing_paren = ret_string:match (romaji .. '%)'); -- has a value if <romaji>); nil else
local romaji_text = romaji:gsub ('%b<>', ''); -- strip html tags
local kern_lead_pattern = '^[jpy]'; -- list of characters that when italicized contact unitalicized leading parenthesis
local kern_tail_pattern = '[dfijkltCEFHIJKMNPR-Z\'"%?!%]]$'; -- list of characters that when italicized contact unitalicized trailing parenthesis
local kern_right = '<span style="margin-right:.2em">(</span>%1'; -- %1 is <romaji> capture
local kern_left = '%1<span style="margin-left:.2em">)</span>'; -- %1 is <romaji> capture
if romaji_has_leading_paren and romaji_text:match (kern_lead_pattern) then
ret_string = ret_string:gsub ('%((' .. romaji .. ')', kern_right); -- replace plain '(' with kerned '('; <romaji> included here to ensure that the correct '(' is kerned
end
if romaji_has_trailing_paren and romaji_text:match (kern_tail_pattern) then
ret_string = ret_string:gsub ('(' .. romaji .. ')%)', kern_left); -- replace plain ')' with kerned ')'; <romaji> included here to ensure that the correct ')' is kerned
end
return ret_string; -- done
end
Line 54 ⟶ 94:
--[=[-------------------------< N I H O N G O >----------------------------------------------------------------
{{Nihongo|<English>|<japanese>|<romaji>|<extra>|<extra2>|lead=yes}}
Line 88 ⟶ 128:
romaji = (lead and english and '[[Hepburn romanization|Hepburn]]: ' or '') .. lang_module._transl ({'ja', 'hepburn', romaji}) or nil;
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)
Line 99 ⟶ 139:
{'%s<5p4n>', {english}}, -- 8 - english
{'%s<5p4n> (%s)', {english, extra}}, -- 9 - english (extra)
{'%s<5p4n> (%s
{'%s<5p4n> (%s, %s)', {english, romaji, extra}},
{'%s<5p4n> (%s)', {english, japanese}}, -- 12 - english (japanese)
{'%s<5p4n> (%s, %s)', {english, japanese, extra}}, -- 13 - english (japanese, extra)
{'%s<5p4n> (%s, %s
{'%s<5p4n> (%s, %s, %s)', {english, japanese, romaji, extra}}, -- 15 - english (japanese, romaji, extra)
}
local ret_string = nihongo_renderer (args, formatting, extra2)
ret_string = romaji_kern (ret_string, romaji); -- kern romaji text when appropriate
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 made as second return value
end
Line 115 ⟶ 157:
--[=[-------------------------< N I H O N G O 3 >--------------------------------------------------------------
Similar to {{nihongo}} but changes rendered order and does not support |lead=
Line 169 ⟶ 211:
--[=[-------------------------< N I H O N G O K R T >--------------------------------------------------------------
Similar to {{nihongo}} but changes rendered order and does not support |lead=
Line 204 ⟶ 246:
{'<5p4n>%s', {japanese}}, -- 4 - japanese
{'<5p4n>%s (%s)', {japanese, extra}}, -- 5 - japanese (extra)
{'<5p4n>%s (%s
{'<5p4n>%s (%s, %s)', {japanese, romaji, extra}}, -- 7 - japanese (romaji, extra)
{'%s<5p4n>', {english}}, -- 8 - english
Line 217 ⟶ 259:
local ret_string = nihongo_renderer (args, formatting, extra2)
ret_string = romaji_kern (ret_string, romaji); -- kern romaji text when appropriate
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 made as second return value
Line 223 ⟶ 266:
--[=[-------------------------< N I H O N G O _ F O O T >------------------------------------------------------
{{Nihongo foot|<English>|<japanese>|<romaji>|<extra>|<extra2>|<post>|lead=yes|group}}
|