Module:Nihongo: Difference between revisions

Content deleted Content added
selective kerning between <english> and reference in {{nihongo foot}};
 
(7 intermediate revisions by 4 users not shown)
Line 10:
local err_msg = {
['nihongo'] = 'Japanese or romaji text required',
['hanyu'] = 'Chinese or pinyin text required',
}
 
local err_cat = {
['nihongo'] = '[[Category:Nihongo template errors]]',
['hanyu'] = '[[Category:Hanyu template errors]]',
}
 
Line 21 ⟶ 19:
--[[--------------------------< 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 spacingcapitalization
 
]]
Line 51 ⟶ 49:
err_msg = err_msg.nihongo,
err_cat = err_cat.nihongo,
},
['hanyu'] = {
tag = 'zh',
system = 'pinyin',
system_link = '[[Pinyin]]',
err_msg = err_msg.hanyu,
err_cat = err_cat.hanyu,
},
['hanyu3'] = {
tag = 'zh',
system = 'pinyin',
err_msg = err_msg.hanyu,
err_cat = err_cat.hanyu,
},
['hanyu hrt'] = {
tag = 'zh',
system = 'pinyin',
err_msg = err_msg.hanyu,
err_cat = err_cat.hanyu,
},
['hanyu foot'] = {
tag = 'zh',
system = 'pinyin',
system_link = '[[Pinyin]]',
err_msg = err_msg.hanyu,
err_cat = err_cat.hanyu,
},
}
Line 138 ⟶ 110:
--[[--------------------------< 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 paranthesisparenthesis
 
In this example, without kerning, the romanized characters 'j' and 'V' are italicized so will contact the parentheses
Line 144 ⟶ 116:
 
<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._transl_xlit() so is not wrapped in parentheses
 
]]
Line 153 ⟶ 125:
end
 
local romanized_text = romanized:gsub ('%b<>', ''):gsub ('\'\'+', ''):gsub ('%[%[', ''):gsub ('%]%]', ''); -- strip htmlHTML tags
 
romanized = romanized:gsub ('([%(%)%.%%%+%-%*%?%[%^%$%]])', '%%%1'); -- escape lua pattern characters
Line 179 ⟶ 151:
--[[--------------------------< C O M M O N >------------------------------------------------------------------
 
Common support for {{nihongo}} and {{hanyu}}
 
render order: is translated (English), native, romanized
Line 195 ⟶ 167:
args[4] = extra or args[4]; -- ensure that extra is 'positional' for use by renderer()
 
local lead = require ('yesModule:yesno' == )(args.lead); -- make boolean
 
if not (native or romanized) then -- not present, return an error message
Line 201 ⟶ 173:
end
if native then
native = lead and lang_module._lang_xx_inherit_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
if romanized then
romanized = (lead and english and (cfg[template].system_link .. ': ') or '') .. lang_module._transl_xlit ({'ja', cfg[template].system, romanized, ['template']=template}) or nil;
end
 
Line 212 ⟶ 185:
{'%s<5p4n> (%s)', {romanized, extra}}, -- 3 - romanized (extra)
{'<5p4n>(%s)', {native}}, -- 4 - native
{'<5p4n>(%s,; %s)', {native, extra}}, -- 5 - (native,; extra)
{'%s<5p4n> (%s)', {romanized, native}}, -- 6 - romanized (native)
{'%s<5p4n> (%s,; %s)', {romanized, native, extra}}, -- 7 - romanized (native,; extra)
{'%s<5p4n>', {english}}, -- 8 - english
{'%s<5p4n> (%s)', {english, extra}}, -- 9 - english (extra)
{'%s<5p4n> (%s)', {english, romanized}}, -- 10 - english (romanized)
{'%s<5p4n> (%s,; %s)', {english, romanized, extra}}, -- 11 - english (romanized,; extra)
{'%s<5p4n> (%s)', {english, native}}, -- 12 - english (native)
{'%s<5p4n> (%s,; %s)', {english, native, extra}}, -- 13 - english (native,; extra)
{'%s<5p4n> (%s, %s)', {english, native, romanized}}, -- 14 - english (native, romanized)
{'%s<5p4n> (%s, %s,; %s)', {english, native, romanized, extra}}, -- 15 - english (native, romanized,; extra)
}
 
Line 235 ⟶ 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 >----------
 
Common support for {{nihongo3}} and {{hanyu3}}
 
render order: is romanized, native, translated (English)
Line 253 ⟶ 226:
return error_message (template);
end
native = native and lang_module._lang ({cfg[template].tag, native, ['template']=template}) or nil;
romanized = romanized and lang_module._transl_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
Line 261 ⟶ 234:
{'%s<5p4n> (%s)', {romanized, extra}}, -- 3 - romanized (extra)
{'<5p4n>(%s)', {native}}, -- 4 - native
{'<5p4n>(%s,; %s)', {native, extra}}, -- 5 - (native,; extra)
{'%s<5p4n> (%s)', {romanized, native}}, -- 6 - romanized (native)
{'%s<5p4n> (%s,; %s)', {romanized, native, extra}}, -- 7 - romanized (native,; extra)
{'%s<5p4n>', {english}}, -- 8 - english
{'%s<5p4n> (%s)', {english, extra}}, -- 9 - english (extra)
{'%s<5p4n> (%s)', {romanized, english}}, -- 10 - romanized (english)
{'%s<5p4n> (%s,; %s)', {romanized, english, extra}}, -- 11 - romanized (english,; extra)
{'%s<5p4n> (%s)', {english, native}}, -- 12 - english (native)
{'%s<5p4n> (%s,; %s)', {english, native, extra}}, -- 13 - english (native,; extra)
{'%s<5p4n> (%s, %s)', {romanized, native, english}}, -- 14 - romanized (native, english)
{'%s<5p4n> (%s, %s,; %s)', {romanized, native, english, extra}}, -- 15 - romanized (native, english,; extra)
}
 
Line 281 ⟶ 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 >----------
 
Common support for {{nihongo krt}} and {{hanyu krt}}
 
render order: is native, romanized, translated (English)
Line 299 ⟶ 272:
return error_message (template);
end
native = native and lang_module._lang ({cfg[template].tag, native, ['template']=template}) or nil;
romanized = romanized and lang_module._transl_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
Line 309 ⟶ 282:
{'<5p4n>%s (%s)', {native, extra}}, -- 5 - native (extra)
{'<5p4n>%s (%s)', {native, romanized}}, -- 6 - native (romanized)
{'<5p4n>%s (%s,; %s)', {native, romanized, extra}}, -- 7 - native (romanized,; extra)
{'%s<5p4n>', {english}}, -- 8 - english
{'%s<5p4n> (%s)', {english, extra}}, -- 9 - english (extra)
{'%s<5p4n> (%s)', {romanized, english}}, -- 10 - romanized (english)
{'%s<5p4n> (%s,; %s)', {romanized, english, extra}}, -- 11 - romanized (english,; extra)
{'<5p4n>%s (%s)', {native, english}}, -- 12 - native (english)
{'<5p4n>%s (%s,; %s)', {native, english, extra}}, -- 13 - native (english,; extra)
{'<5p4n>%s (%s, %s)', {native, romanized, english}}, -- 14 - native (romanized, english)
{'<5p4n>%s (%s, %s,; %s)', {native, romanized, english, extra}}, -- 15 - native (romanized, english,; extra)
}
 
Line 329 ⟶ 302:
--[[--------------------------< C O M M O N _ F O O T >--------------------------------------------------------
 
Common support for {{nihongo foot}} and {{hanyu foot}}
 
render order: is English<ref>native, romanized</ref>
Line 346 ⟶ 319:
local group = args.group;
local ref_name = args.ref_name
local lead = require ('yesModule:yesno' == )(args.lead); -- make boolean
 
if not (native or romanized) then -- not present, return an error message
Line 352 ⟶ 325:
end
if native then
native = lead and lang_module._lang_xx_inherit_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
if romanized then
romanized = (lead and (cfg[template].system_link .. ': ') or '') .. lang_module._transl_xlit ({'ja', cfg[template].system, romanized, ['template']=template}) or nil;
end
Line 361 ⟶ 335:
{'%s', {extra}}, -- 1 - extra
{'%s', {romanized}}, -- 2 - romanized
{'%s,; %s', {romanized, extra}}, -- 3 - romanized,; extra
{'%s', {native}}, -- 4 - native
{'%s,; %s', {native, extra}}, -- 5 - native,; extra
{'%s, %s', {native, romanized}}, -- 6 - native romanized
{'%s, %s,; %s', {native, romanized, extra}}, -- 7 - native romanized,; extra
-- from here english is used in the mapping but not rendered by renderer so not included in the table
{'', {''}}, -- 8 - english
{'%s', {extra}}, -- 9 - extra
{'%s', {romanized}}, -- 10 - romanized
{'%s,; %s', {romanized, extra}}, -- 11 - romanized,; extra
{'%s', {native}}, -- 12 - native
{'%s,; %s', {native, extra}}, -- 13 - native,; extra
{'%s, %s', {native, romanized}}, -- 14 - native romanized
{'%s, %s,; %s', {native, romanized, extra}}, -- 15 - native romanized,; extra
}
 
Line 416 ⟶ 390:
<extra> is rendered as presented preceeded with <comma><space>
<extra2> is rendered as presented preceeded with <space>
|lead=: takes one value 'yes'; renders language name same as {{lang-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 438 ⟶ 412:
<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> is rendered as presented preceededpreceded with <comma><space>
<extra2> is rendered as presented preceededpreceded with <space>
 
]=]
Line 461 ⟶ 435:
<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> is rendered as presented preceededpreceded with <comma><space>
<extra2> is rendered as presented preceededpreceded with <space>
 
]=]
Line 482 ⟶ 456:
<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> is rendered as presented preceededpreceded with <comma><space>
<extra2> is rendered as presented preceededpreceded with <space>
<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 {{lang-langx|ja}} but also adds [[Hepburn romanization|Hepburn]]:<space> ahead of the romanization;
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)
Line 494 ⟶ 468:
local function nihongo_foot (frame)
return common_foot (frame, 'nihongo foot')
end
 
 
--[=[-------------------------< H A N Y U >--------------------------------------------------------------------
 
Implement {{hanyu}} using Module:Lang for language and transliteration markup
 
{{hanyu|<English>|<chinese>|<pinyin>|<extra>|<extra2>|lead=yes}}
 
<English>, <chinese>, and <pinyin> are positional parameters
<English>: rendered as presented; purports to be English translation of <kanji/kana>
<chinese>: Chinese language text using Chinese script; TODO: require?
<pinyin>: Pinyin romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Pinyin romanization'?
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic
<extra> is rendered as presented preceeded with <comma><space>
<extra2> is rendered as presented preceeded with <space>
|lead=: takes one value 'yes'; renders language name same as {{lang-zh}} but also adds [[Pinyin]]:<space> ahead of the romanization; TODO: in Module:Lang, turnoff tooltip for transl when |lead=yes
 
]=]
 
local function hanyu (frame)
return common (frame, 'hanyu')
end
 
 
--[=[-------------------------< H A N Y U 3 >------------------------------------------------------------------
 
Implement {{hanyu3}} using Module:Lang for language and transliteration markup
 
Similar to {{hanyu}} but changes rendered order and does not support |lead=
 
{{hanyu3|<English>|<chinese>|<pinyin>|<extra>|<extra2>}}
 
<English>, <chinese>, and <pinyin> are positional parameters
<English>: rendered as presented; purports to be English translation of <kanji/kana>
<chinese>: Chinese language text using Chinese script; TODO: require?
<pinyin>: Pinyin romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Pinyin romanization'?
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic
<extra> is rendered as presented preceeded with <comma><space>
<extra2> is rendered as presented preceeded with <space>
 
]=]
 
local function hanyu3 (frame)
return common_romanized_native_translated (frame, 'hanyu3')
end
 
 
--[=[-------------------------< H A N Y U _ H R T >------------------------------------------------------------
 
Implement {{hanyu hrt}} using Module:Lang for language and transliteration markup
 
Similar to {{hanyu}} but changes rendered order and does not support |lead=
 
{{hanyu krt|<English>|<chinese>|<pinyin>|<extra>|<extra2>}}
 
<English>, <chinese>, and <pinyin> are positional parameters
<English>: rendered as presented; purports to be English translation of <kanji/kana>
<chinese>: Chinese language text using Chinese script; TODO: require?
<pinyin>: Pinyin romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Pinyin romanization'?
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic
<extra> is rendered as presented preceeded with <comma><space>
<extra2> is rendered as presented preceeded with <space>
 
]=]
 
local function hanyu_hrt (frame)
return common_native_romanized_translated (frame, 'hanyu hrt')
end
 
 
--[=[-------------------------< H A N Y U _ F O O T >----------------------------------------------------------
 
Implement {{hanyu_foot}} using Module:Lang for language and transliteration markup
 
{{hanyu foot|<English>|<chinese>|<pinyin>|<extra>|<extra2>|<post>|lead=yes|group}}
 
<English>, <chinese>, and <pinyin> are positional parameters
<English>: rendered as presented; purports to be English translation of <kanji/kana>
<chinese>: Chinese language text using Chinese script; TODO: require?
<pinyin>: Pinyin romanization (transliteration); TODO: in Module:Lang/data change tooltip text to 'Pinyin romanization'?
<extra> and <extra2> are positional or named: |extra= and |extra2=; mixing can be problematic
<extra> is rendered as presented preceeded with <comma><space>
<extra2> is rendered as presented preceeded with <space>
<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 {{lang-zh}} but also adds [[Pinyin]]:<space> ahead of the romanization;
TODO: in Module:Lang, turnoff tooltip for transl when |lead=yes
in the live template |lead= also adds the Help:Installing Chinese character sets link; this is not supported in this code (hanyu nor hanyu3 have this support)
|group=: the group attribute in <ref group="..."> and in {{reflist}}
 
]=]
 
local function hanyu_foot (frame)
return common_foot (frame, 'hanyu foot')
end
 
Line 597 ⟶ 477:
nihongo = nihongo,
nihongo3 = nihongo3,
nihongokrt = nihongo_krt, -- TODO: rename function name in {{#invoke}} to use nihongo_krt; delete this line
nihongo_krt = nihongo_krt,
nihongo_foot = nihongo_foot,
hanyu = hanyu,
hanyu3 = hanyu3,
hanyu_hrt = hanyu_hrt,
hanyu_foot = hanyu_foot,
}