Module:Nihongo: Difference between revisions
Created page with "require('strict'); --[[--------------------------< E R R O R _ M E S S A G E S >-------------------------------------------------- error messaging; keys to this table are the template base names: 'nihongo', 'nihongo3', 'nihongo krt', 'nihongo foot' → 'nihongo' etc ]] local err_msg = { ['nihongo'] = 'Japanese or romaji text required', ['hanyu'] = 'Chinese or pinyin text required', } local err_cat = { ['nihongo'] = 'Category:Nihongo template errors', ['han..." |
No edit summary |
||
Line 10: | Line 10: | ||
local err_msg = { | local err_msg = { | ||
['nihongo'] = 'Japanese or romaji text required', | ['nihongo'] = 'Japanese or romaji text required', | ||
} | } | ||
local err_cat = { | local err_cat = { | ||
['nihongo'] = '[[Category:Nihongo template errors]]', | ['nihongo'] = '[[Category:Nihongo template errors]]', | ||
} | } | ||
Line 21: | Line 19: | ||
--[[--------------------------< C O N F I G U R A T I O N >---------------------------------------------------- | --[[--------------------------< C O N F I G U R A T I O N >---------------------------------------------------- | ||
configuration setting for the various templates. keys to this table are the template names without | configuration setting for the various templates. keys to this table are the template names without capitalization | ||
]] | ]] | ||
Line 51: | Line 49: | ||
err_msg = err_msg.nihongo, | err_msg = err_msg.nihongo, | ||
err_cat = err_cat.nihongo, | err_cat = err_cat.nihongo, | ||
}, | }, | ||
} | } | ||
Line 138: | Line 110: | ||
--[[--------------------------< R O M A N I Z E D _ K E R N >-------------------------------------------------- | --[[--------------------------< R O M A N I Z E D _ K E R N >-------------------------------------------------- | ||
Add kerning when first or last character of romanized text contacts adjacent opening or closing | Add kerning when first or last character of romanized text contacts adjacent opening or closing parenthesis | ||
In this example, without kerning, the romanized characters 'j' and 'V' are italicized so will contact the parentheses | In this example, without kerning, the romanized characters 'j' and 'V' are italicized so will contact the parentheses | ||
Line 144: | Line 116: | ||
<ret_string> is the formatted template output (except that the magic string '<5p4n>' has not yet been replaced) | <ret_string> is the formatted template output (except that the magic string '<5p4n>' has not yet been replaced) | ||
<romanized> is the return from lang_module. | <romanized> is the return from lang_module._xlit() so is not wrapped in parentheses | ||
]] | ]] | ||
Line 153: | Line 125: | ||
end | end | ||
local romanized_text = romanized:gsub ('%b<>', ''):gsub ('\'\'+', ''):gsub ('%[%[', ''):gsub ('%]%]', ''); -- strip | local romanized_text = romanized:gsub ('%b<>', ''):gsub ('\'\'+', ''):gsub ('%[%[', ''):gsub ('%]%]', ''); -- strip HTML tags | ||
romanized = romanized:gsub ('([%(%)%.%%%+%-%*%?%[%^%$%]])', '%%%1'); -- escape lua pattern characters | romanized = romanized:gsub ('([%(%)%.%%%+%-%*%?%[%^%$%]])', '%%%1'); -- escape lua pattern characters | ||
Line 179: | Line 151: | ||
--[[--------------------------< C O M M O N >------------------------------------------------------------------ | --[[--------------------------< C O M M O N >------------------------------------------------------------------ | ||
Common support for {{nihongo | Common support for {{nihongo}} | ||
render order: is translated (English), native, romanized | render order: is translated (English), native, romanized | ||
Line 195: | Line 167: | ||
args[4] = extra or args[4]; -- ensure that extra is 'positional' for use by renderer() | args[4] = extra or args[4]; -- ensure that extra is 'positional' for use by renderer() | ||
local lead = ' | local lead = require ('Module:yesno')(args.lead); -- make boolean | ||
if not (native or romanized) then -- not present, return an error message | if not (native or romanized) then -- not present, return an error message | ||
Line 201: | Line 173: | ||
end | end | ||
if native then | if native then | ||
native = lead and lang_module. | native = lead and lang_module._langx ({['code']=cfg[template].tag, ['text']=native, ['template']=template}) or | ||
lang_module._lang ({cfg[template].tag, native, ['template']=template}); -- add ja script with/without language prefix | |||
end | end | ||
if romanized then | if romanized then | ||
romanized = (lead and english and (cfg[template].system_link .. ': ') or '') .. lang_module. | romanized = (lead and english and (cfg[template].system_link .. ': ') or '') .. lang_module._xlit ({'ja', cfg[template].system, romanized, ['template']=template}) or nil; | ||
end | end | ||
Line 235: | Line 208: | ||
--[[--------------------------< C O M M O N _ R O M A N I Z E D _ N A T I V E _ T R A N S L A T E D >---------- | --[[--------------------------< C O M M O N _ R O M A N I Z E D _ N A T I V E _ T R A N S L A T E D >---------- | ||
Common support for {{nihongo3 | Common support for {{nihongo3}} | ||
render order: is romanized, native, translated (English) | render order: is romanized, native, translated (English) | ||
Line 253: | Line 226: | ||
return error_message (template); | return error_message (template); | ||
end | end | ||
native = native and lang_module._lang ({cfg[template].tag, native}) or nil; | native = native and lang_module._lang ({cfg[template].tag, native, ['template']=template}) or nil; | ||
romanized = romanized and lang_module. | romanized = romanized and lang_module._xlit ({cfg[template].tag, cfg[template].system, romanized, ['template']=template}) or nil; | ||
local formatting = { -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, replaced before function returns | local formatting = { -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, replaced before function returns | ||
Line 281: | Line 254: | ||
--[[--------------------------< C O M M O N _ N A T I V E _ R O M A N I Z E D _ T R A N S L A T E D >---------- | --[[--------------------------< C O M M O N _ N A T I V E _ R O M A N I Z E D _ T R A N S L A T E D >---------- | ||
Common support for {{nihongo | Common support for {{nihongo krt}} | ||
render order: is native, romanized, translated (English) | render order: is native, romanized, translated (English) | ||
Line 299: | Line 272: | ||
return error_message (template); | return error_message (template); | ||
end | end | ||
native = native and lang_module._lang ({cfg[template].tag, native}) or nil; | native = native and lang_module._lang ({cfg[template].tag, native, ['template']=template}) or nil; | ||
romanized = romanized and lang_module. | romanized = romanized and lang_module._xlit ({cfg[template].tag, cfg[template].system, romanized, ['template']=template}) or nil; | ||
local formatting = { -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, replaced before function returns | local formatting = { -- <5p4n> and </5p4n>: place holders for font-weight style spans; akin to stripmarkers, replaced before function returns | ||
Line 329: | Line 302: | ||
--[[--------------------------< C O M M O N _ F O O T >-------------------------------------------------------- | --[[--------------------------< C O M M O N _ F O O T >-------------------------------------------------------- | ||
Common support for {{nihongo | Common support for {{nihongo foot}} | ||
render order: is English<ref>native, romanized</ref> | render order: is English<ref>native, romanized</ref> | ||
Line 346: | Line 319: | ||
local group = args.group; | local group = args.group; | ||
local ref_name = args.ref_name | local ref_name = args.ref_name | ||
local lead = ' | local lead = require ('Module:yesno')(args.lead); -- make boolean | ||
if not (native or romanized) then -- not present, return an error message | if not (native or romanized) then -- not present, return an error message | ||
Line 352: | Line 325: | ||
end | end | ||
if native then | if native then | ||
native = lead and lang_module. | native = lead and lang_module._langx ({['code']=cfg[template].tag, ['text']=native, ['template']=template}) or | ||
lang_module._lang ({cfg[template].tag, native, ['template']=template}); -- add ja script with/without language prefix | |||
end | end | ||
if romanized then | if romanized then | ||
romanized = (lead and (cfg[template].system_link .. ': ') or '') .. lang_module. | romanized = (lead and (cfg[template].system_link .. ': ') or '') .. lang_module._xlit ({'ja', cfg[template].system, romanized, ['template']=template}) or nil; | ||
end | end | ||
Line 388: | Line 362: | ||
local content = renderer (args, formatting, extra2); | local content = renderer (args, formatting, extra2); | ||
content = content:gsub ('<5p4n>', ''):gsub ('</5p4n>$', '', 1); -- strip secret <5p4n> and </5p4n> tags added by renderer(); spans not used by this template | content = content:gsub ('<5p4n>', ''):gsub ('</5p4n>$', '', 1); -- strip secret <5p4n> and </5p4n> tags added by renderer(); spans not used by this template | ||
if english:match ('\'\'+$') then -- if <english> is italic, bold, or both | |||
local text = english:gsub ('%b<>', ''):gsub ('\'\'+', ''):gsub ('%[%[', ''):gsub ('%]%]', ''); -- strip markup | |||
if text:match ('[dfijkltCEFHIJKMNPR-Z\'"%?!%]]$') then -- when <english> ends with one of these characters | |||
english = '<span style="margin-right:.09em">' .. english .. '</span>'; -- add kerning | |||
end | |||
end | |||
return english .. frame:extensionTag ({name='ref', args={group=group, name=ref_name}, content=content}); -- english with attached reference tag | return english .. frame:extensionTag ({name='ref', args={group=group, name=ref_name}, content=content}); -- english with attached reference tag | ||
Line 409: | Line 390: | ||
<extra> is rendered as presented preceeded with <comma><space> | <extra> is rendered as presented preceeded with <comma><space> | ||
<extra2> is rendered as presented preceeded with <space> | <extra2> is rendered as presented preceeded with <space> | ||
|lead=: takes one value 'yes'; renders language name same as {{ | |lead=: takes one value 'yes'; renders language name same as {{langx|ja}} but also adds [[Hepburn romanization|Hepburn]]:<space> ahead of the romanization; TODO: in Module:Lang, turnoff tooltip for transl when |lead=yes | ||
]=] | ]=] | ||
Line 431: | Line 412: | ||
<romaji>: Hepburn romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Hepburn romanization'? | <romaji>: Hepburn romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Hepburn romanization'? | ||
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic | <extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic | ||
<extra> is rendered as presented | <extra> is rendered as presented preceded with <comma><space> | ||
<extra2> is rendered as presented | <extra2> is rendered as presented preceded with <space> | ||
]=] | ]=] | ||
Line 454: | Line 435: | ||
<romaji>: Hepburn romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Hepburn romanization'? | <romaji>: Hepburn romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Hepburn romanization'? | ||
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic | <extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic | ||
<extra> is rendered as presented | <extra> is rendered as presented preceded with <comma><space> | ||
<extra2> is rendered as presented | <extra2> is rendered as presented preceded with <space> | ||
]=] | ]=] | ||
Line 475: | Line 456: | ||
<romaji>: Hepburn romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Hepburn romanization'? | <romaji>: Hepburn romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Hepburn romanization'? | ||
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic | <extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic | ||
<extra> is rendered as presented | <extra> is rendered as presented preceded with <comma><space> | ||
<extra2> is rendered as presented | <extra2> is rendered as presented preceded with <space> | ||
<post> is positional or named: |post= is a postscript character preceding the <ref>..</ref> tag (after <English>) | <post> is positional or named: |post= is a postscript character preceding the <ref>..</ref> tag (after <English>) | ||
|lead=: takes one value 'yes'; renders language name same as {{ | |lead=: takes one value 'yes'; renders language name same as {{langx|ja}} but also adds [[Hepburn romanization|Hepburn]]:<space> ahead of the romanization; | ||
TODO: in Module:Lang, turnoff tooltip for transl when |lead=yes | TODO: in Module:Lang, turnoff tooltip for transl when |lead=yes | ||
in the live template |lead= also adds the Help:Installing Japanese character sets link; this is not supported in this code (nihongo nor nihongo3 have this support) | in the live template |lead= also adds the Help:Installing Japanese character sets link; this is not supported in this code (nihongo nor nihongo3 have this support) | ||
Line 487: | Line 468: | ||
local function nihongo_foot (frame) | local function nihongo_foot (frame) | ||
return common_foot (frame, 'nihongo foot') | return common_foot (frame, 'nihongo foot') | ||
end | end | ||
Line 590: | Line 477: | ||
nihongo = nihongo, | nihongo = nihongo, | ||
nihongo3 = nihongo3, | nihongo3 = nihongo3, | ||
nihongo_krt = nihongo_krt, | nihongo_krt = nihongo_krt, | ||
nihongo_foot = nihongo_foot, | nihongo_foot = nihongo_foot, | ||
} | } |