Module:kanjitab
Jump to navigation
Jump to search
- The followingdocumentationis located atModule:kanjitab/documentation.[edit]
- Useful links:subpage list•links•transclusions•testcases•sandbox
This module generates the content of{{ja-kanjitab}}
,{{ryu-kanjitab}}
etc.
Testcases
Kanjiin this term |
---|
Hoài |
なつ Grade: S |
kun'yomi |
Alternative spelling |
---|
Hoài かしい(kyūjitai) |
Kanjiin this term | |
---|---|
Thủ | Đế |
と(り) Grade: 3 |
し(まり) Grade: S |
kun'yomi |
Kanjiin this term | |
---|---|
Nhật | Phó |
ひ Grade: 1 |
つ(け) > づ(け) Grade: 4 |
kun'yomi |
Kanjiin this term | |
---|---|
Quan | Hệ |
かん Grade: 4 |
けい Grade: 3 |
kan'on |
Alternative spelling |
---|
Quan hệ(kyūjitai) |
Kanjiin this term | |
---|---|
Đông | Kinh |
とう Grade: 2 |
きょう Grade: 2 |
kan'on | goon |
Kanjiin this term | |||
---|---|---|---|
Đại | Hòa | Ngôn | Diệp |
やまと | こと Grade: 2 |
は > ば Grade: 3 | |
Grade: 1 | Grade: 3 | ||
jukujikun | kun'yomi |
Kanjiin this term | |||
---|---|---|---|
Diệt | Trà | Khổ | Trà |
め Grade: S (ateji) |
ちゃ Grade: 2 (ateji) |
く Grade: 3 (ateji) |
ちゃ Grade: 2 (ateji) |
irregular | kan'yōon | goon | kan'yōon |
Kanjiin this term | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | Phất | Lợi | Gia | Hệ | Á | Mễ | Lợi | Gia | Nhân |
あ Jinmeiyō (ateji) |
ふつ > ふ Hyōgai (ateji) |
り Grade: 4 (ateji) |
か Grade: 4 (ateji) |
けい Grade: 6 |
あ Grade: S (ateji) |
め Grade: 2 (ateji) |
り Grade: 4 (ateji) |
か Grade: 4 (ateji) |
じん Grade: 1 |
on'yomi | irregular | on'yomi | kan'on | kan'on | kan'on | irregular | on'yomi | kan'on | kan'on |
Alternative spelling |
---|
A phất lợi gia hệ á mễ lợi gia nhân(kyūjitai) |
{{ja-kanjitab|pagename= đại hòa ngôn diệp |||こと|は|k4=ば|yomi=juku2,k2}} {{ja-kanjitab|pagename= đại hòa ngôn diệp |やまと2|こと|は|k3=ば|yomi=juku2,k2}} // "3" is # of argument, not # of kanji
localexport={}
localm_str_utils=require("Module:string utilities")
localm_utilities=require("Module:utilities")
localm_ja=require("Module:ja")
localshow_labels=require("Module:labels").show_labels
--[=[
Other modules used: [[Module:parameters]]
]=]
localconcat=table.concat
localconvert_iteration_marks=require("Module:Hani").convert_iteration_marks
localfind=string.find
localgsplit=m_str_utils.gsplit
localgsub=string.gsub
localkata_to_hira=m_ja.kata_to_hira
localinsert=table.insert
localmatch=string.match
localremove=table.remove
localsplit=m_str_utils.split
localsub=string.sub
localugsub=mw.ustring.gsub
localulen=m_str_utils.len
localumatch=mw.ustring.match
localusub=m_str_utils.sub
localPAGENAME=mw.loadData("Module:headword/data").pagename
localNAMESPACE=mw.title.getCurrentTitle().nsText
locald_range=mw.loadData("Module:ja/data/range")
localyomi_data=mw.loadData("Module:kanjitab/data")
localkanji_grade_links={
"[[Appendix:Japanese_glossary#kyōiku_kanji|Grade: 1]]",
"[[Appendix:Japanese_glossary#kyōiku_kanji|Grade: 2]]",
"[[Appendix:Japanese_glossary#kyōiku_kanji|Grade: 3]]",
"[[Appendix:Japanese_glossary#kyōiku_kanji|Grade: 4]]",
"[[Appendix:Japanese_glossary#kyōiku_kanji|Grade: 5]]",
"[[Appendix:Japanese_glossary#kyōiku_kanji|Grade: 6]]",
"[[Appendix:Japanese_glossary#jōyō_kanji|Grade: S]]",-- 7
"[[Appendix:Japanese_glossary#jinmeiyō_kanji|Jinmeiyō]]",-- 8
"[[Appendix:Japanese_glossary#hyōgai_kanji|Hyōgai]]"-- 9
}
-- this is the function that is called from templates
functionexport.show(frame)
localargs=require("Module:parameters").process(frame:getParent().args,{
[1]={list=true,allow_holes=true},
k={list=true,allow_holes=true},
o={list=true,allow_holes=true},
r={},
sort={},
yomi={},
ateji={},
alt={},
alt2={},
kyu={list=true},
y={alias_of="yomi"},
clearright={type="boolean"},
pagename={},
})
locallang_code=frame.args[1]
locallang=require("Module:languages").getByCode(lang_code)
locallang_name=lang:getCanonicalName()
ifargs.pagenameandNAMESPACE==""then
require("Module:debug/track")("kanjitab/pagename param in mainspace")
end
localpagename=args.pagenameorPAGENAME
localcategories={}
localcells={}
-- extract kanji and non-kanji
localkanji={}
localnon_kanji={}
-- 々 and 〻
pagename=convert_iteration_marks(pagename)
localkanji_border=1
ugsub(pagename,"()(["..d_range.kanji.."々〻])()",function(p1,w1,p2)
insert(non_kanji,usub(pagename,kanji_border,p1-1))
kanji_border=p2
insert(kanji,w1)
end)
insert(non_kanji,usub(pagename,kanji_border))
-- kyujitai
localkyu=args.kyu
ifkyu[1]=="-"then
kyu={}
elseifkyu[1]==nilthen
localform_kyu={non_kanji[1]}
localkyu_data=mw.loadData("Module:ja/data/kyu")
localhas_kyu,has_kyu_nonsupple,has_shin=false,false,false
fori,vinipairs(kanji)do
localv_kyu=match(kyu_data[1],v.."(%S*)%s")
ifv_kyu==nilthen
insert(form_kyu,v)
elseifv_kyu==""then
has_shin=true
break
elseifv_kyu:sub(1,1)=="&"then
has_kyu=true
insert(form_kyu,v_kyu)
else
has_kyu,has_kyu_nonsupple=true,true
insert(form_kyu,v_kyu)
end
insert(form_kyu,non_kanji[i+1])
end
ifnothas_shinandhas_kyuthen
kyu[1]=(has_kyu_nonsuppleand""orpagename.."|")..concat(form_kyu)
end
iffind(pagename,"Biện")then
require("Module:debug/track")("kanjitab/ambiguous kyujitai for biện")
kyu[1]="which biện?"
end
end
localall_yomi,missing_yomi
ifargs.yomithen
all_yomi={}
localkeys=split(args.yomi,",")
fori,yomi,leninipairs(keys)do
yomi,len=match(yomi,"^(%l*)(%d*)$")
yomi=yomi_data[yomi]orerror("The yomi type\ ""..yomi.."\ "in the input\ ""..args.yomi.."\ "is not recognized. ")
iflen~=""then
-- Disallow length 0 or leading zeroes, as a sanity check.
len=match(len,"^[1-9]%d*$")andtonumber(len)orerror("Cannot specify a length of"..len.."kanji.")
-- Only one yomi with no length given: apply to all kanji.
elseifi==1and#keys==1then
len=#kanji
else
len=1
end
localyomi_type=yomi.type
-- If the on'yomi is not specified as goon/kanon/toon/soon, only "on".
ifyomi_type=="on'yomi"then
require("Module:debug/track")("kanjitab/unspecified on")
elseifyomi_type=="jūbakoyomi"then
require("Module:debug/track")("kanjitab/jubakoyomi")
elseifyomi_type=="yutōyomi"then
require("Module:debug/track")("kanjitab/yutoyomi")
end
-- If the yomi requires a specific number of kanji (e.g. jūbakoyomi, yutōyomi).
localreq_kanji=yomi.required_kanji
ifreq_kanjiand#kanji~=req_kanjithen
error("The yomi type\ ""..yomi.type.."\ "is only applicable to terms with "..req_kanji.."kanji.")
elseifyomi.type=="none"then
missing_yomi=true
end
-- Insert yomi data for each applicable kanji. Wrap in a table first, as the range for this input yomi is determined by its identity, so that (e.g.) "kun,kun" is still treated as two separate inputs.
yomi={data=yomi}
for_=1,lendo
insert(all_yomi,yomi)
end
end
-- If there are any yomi slots left, handle them as empty.
if#all_yomi<#kanjithen
missing_yomi=true
for_=#all_yomi+1,#kanjido
insert(all_yomi,{data=yomi_data.none})
end
end
elseif#kanji>0then
missing_yomi=true
end
ifmissing_yomithen
insert(categories,lang_name.."terms with missing yomi")
end
-- process readings
localreadings={}
localreadings_actual={}
localreading_length_total=0
fori=1,args[1].maxindexdo
localreading_kana,reading_length=match(args[1][i]or"","^(%D*)(%d*)$")
reading_kana=reading_kana~=""andreading_kanaornil
reading_length=reading_kanaandtonumber(reading_length)or1
insert(readings,{reading_kana,reading_length})
reading_length_total=reading_length_total+reading_length
end
ifreading_length_total>#kanjithen
error("Readings for"..reading_length_total.."kanji are given, but this word has only"..#kanji.."kanji.")
else
for_=reading_length_total+1,#kanjido
insert(readings,{nil,1})
end
end
localtable_head=[=[
{| class= "wikitable kanji-table floatright" style= "text-align: center; ]=]..(args.clearrightand"clear:right;"or"")..[=[ "
!]=]..(#kanji>1and"colspan=\ ""..#kanji.."\ ""or"")..[=[style= "font-weight: normal;" | [[Appendix:Japanese_glossary#kanji|Kanji]] in this term
|- lang= "]=]..lang_code..[=[ "class=" Jpan "style=" font-size: 2em; background: var(--wikt-palette-white,#ffffff); color: inherit; line-height: 1em; "
]=]
ifargs.k.maxindexandargs.k.maxindex>args[1].maxindexthen
error("kanjitab/too many k")
end
ifargs.o.maxindexandargs.o.maxindex>args[1].maxindexthen
error("kanjitab/too many o")
end
localis_ateji={}
ifargs.atejithen
localateji=args.ateji
localcat_ateji=false
ifateji=="y"then
fori=1,#kanjido
is_ateji[i]=true
end
cat_ateji=true
else
foriingsplit(ateji,";")do
gsub(i,"^(%d+)$",function(a)
is_ateji[tonumber(a)]=true
cat_ateji=true
end)
gsub(i,"^(%d+),(%d+)$",function(a,b)
forj=tonumber(a),tonumber(b)do
is_ateji[j]=true
end
cat_ateji=true
end)
end
end
ifcat_atejitheninsert(categories,lang_name.."terms spelled with ateji")end
end
-- if hiragana readings were passed,
-- make the "spelled with..." categories, the readings cells on the lower level and build the sort key
-- otherwise rely on the pagename to make the original kanjitab and categories
localcells_above={}
localcells_below={}
localkanji_pos=1
fori,readinginipairs(readings)do
localreading_kana,reading_length=reading[1],reading[2]
localcell={}
ifreading_length<=1then
insert(cell,"| rowspan=\ "2\ "| ")
else
insert(cell,"| colspan =\ ""..reading_length.."\ "| ")
end
-- display reading, actual reading and okurigana
ifreading_kanathen
ifreading_kana~=""andreading_kana~="-"andumatch(reading_kana,"[^"..d_range.kana.."]")then
error("Please remove any non-kana characters from the reading input"..reading_kana..".")
end
localactual_reading=args.k[i]
localokurigana=args.o[i]
localokurigana_text=okuriganaand"("..okurigana..")"or""
localactual_reading_text=actual_readingand">"..actual_reading..okurigana_textor""
localtext=reading_kana..okurigana_text..actual_reading_text
readings_actual[i]={(actual_readingorreading_kana)..(okuriganaor""),reading_length}
insert(cell,"<span class=\ "Jpan\ "lang=\ ""..lang_code.."\ "> "..text.."</span>")
ifreading_length<=1theninsert(cell,"<br/>")end
else
readings_actual[i]={nil,1}
end
-- display kanji grade, categorize
forj=kanji_pos,kanji_pos+reading_length-1do
localsingle_kanji=kanji[j]
localkanji_grade=m_ja.kanji_grade(single_kanji)
localateji_text=is_ateji[j]and"<br/><small>([[Appendix:Japanese glossary#ateji|ateji]])</small>"or""
localtype,compound
ifall_yomithen
localyomi=all_yomi[j].data
type,compound=yomi.type,yomi.compound_reading
end
ifnotreading_kanathen
iftype~="irregular"then
require("Module:debug/track")("kanjitab/no reading")
end
insert(categories,lang_name.."terms spelled with"..single_kanji)
elseifreading_length~=1ortype=="irregular"then
insert(categories,lang_name.."terms spelled with"..single_kanji)
elseifcompoundthen
-- Re-enable once all bad jukujikun calls are fixed.
-- error( "The yomi type \" ".. type.." \ "is only applicable to compound character readings, so cannot apply to".. single_kanji.. "read as".. reading_kana.. ". If this is intended as part of a".. type.. "reading, please enter the whole reading as one, followed by the number of kanji it applies to." )
require("Module:debug/track")("kanjitab/single kanji with jukujikun")
else-- Subcategorize by reading.
insert(categories,lang_name.."terms spelled with"..single_kanji.."read as"..kata_to_hira(reading_kana))
end
ifreading_length<=1then
insert(cell,"<small>"..kanji_grade_links[kanji_grade].."</small>"..ateji_text)
else
insert(cells_below,"| <small>"..kanji_grade_links[kanji_grade].."</small>"..ateji_text)
end
end
insert(cells_above,concat(cell))
kanji_pos=kanji_pos+reading_length
end
insert(cells,"|- style=\ "background: var(--wikt-palette-white,#ffffff); color: inherit;\ "")
if#cells_below>0then
insert(cells,concat(cells_above,"\n"))
insert(cells,"|- style=\ "background: var(--wikt-palette-white,#ffffff); color: inherit;\ "")
insert(cells,concat(cells_below,"\n"))
else
fori,vinipairs(cells_above)do
cells_above[i]=gsub(v,"| rowspan=\ "2\ "| ","|")
end
insert(cells,concat(cells_above,"\n"))
end
localrendaku=args.r
ifrendakuthen
insert(categories,lang_name.."terms with rendaku")
end
ifall_yomithen
insert(cells,"|-")
locallen,all_on,yomi_cat=1,true
fori,yomiinipairs(all_yomi)do
-- If the next kanji has the same yomi table, it's part of the same range.
ifyomi==all_yomi[i+1]then
len=len+1
else
yomi=yomi.data
localyomi_type=yomi.type
localdisplay=yomi.displayoryomi_type
localappendix=yomi.appendix
insert(cells,"| colspan=\ ""..len.."\ "| "..(
appendix==falseanddisplayor
"[[Appendix:Japanese_glossary#"..(appendixoryomi_type).."|"..display.."]]"
))
-- Categorise as irregular if any irregular yomi are found; otherwise, categorise if all yomi are of the same type. If yomi are of different types but are all on, on'yomi is used as a fallback.
ifyomi_cat~="irregular"then
localcat_type=yomi_type
ifcat_type=="irregular"oryomi_cat==nilthen
yomi_cat=cat_type
elseifyomi_cat~=cat_typethen
yomi_cat=false
end
ifnotyomi.onyomithen
all_on=false
end
end
len=1
end
end
ifyomi_catthen
-- Check yomi_data first, in case cat_type is "irregular"; if no match, must be some other type, so get it from the first yomi in all_yomi, since not all yomi types are yomi_data keys.
yomi_cat=yomi_data[yomi_cat]orall_yomi[1].data
elseifall_onthen
yomi_cat=yomi_data.on
elseif#all_yomi==2then
localy1,y2=all_yomi[1].data,all_yomi[2].data
ifulen(pagename)==2then
ify1.onyomiandy2.type=="kun'yomi"then
yomi_cat=yomi_data.j-- jūbakoyomi
elseify1.type=="kun'yomi"andy2.onyomithen
yomi_cat=yomi_data.y-- yutōyomi
end
end
end
ifyomi_catthen
localcategory=yomi_cat.reading_category
ifcategory~=falsethen
insert(categories,lang_name.."".."terms read with"..(categoryoryomi_cat.type))
end
end
end
localkanji_table
if#kanji>0then
kanji_table=table_head
for_,vinipairs(kanji)do
kanji_table=kanji_table.."| style=\ "padding: 0.5em;\ "| [[ "..v.."#"..lang_name.."|"..v.."]]\n"
end
kanji_table=kanji_table..concat(cells,"\n").."\n|} "
else
kanji_table=""
end
localforms_table=""
ifargs.alt==""orargs.alt=="-"thenargs.alt=nilend
ifkyu[1]orargs.altthen
localforms={}
-- |kyu=
ifkyu[1]=="which biện?"then
insert(forms,"<strong class=\ "error\ "style=\ "font-size:75%;\ ">Please specify the correct kyujitai for biện with the parameter\ "kyu\ ".</strong>[[Category:Requests for cleanup in "..lang_name.."entries]]")
remove(kyu,1)
end
for_,forminipairs(kyu)do
localform_linkto,form_display=match(form,"^(.+)|(.+)$")
ifnotform_linktothenform_linkto,form_display=form,formend
insert(forms,concat{
"<span class=\ "Jpan\ "lang=\ ""..lang_code.."\ "style=\ "font-family: Du ゴシック, HanaMinA, sans-serif; font-size:140%;\ ">[[ ",
form_linkto,
form_linkto==pagenameand"|"or"#"..lang_name.."|",
form_display,
"]]</span> <small>",
show_labels{labels={"kyūjitai"},lang=lang,nocat=true},
"</small>",
})
end
-- |alt=
ifargs.altthen
forformingsplit(args.alt,",")do
locali_semicolon=find(form,":")
ifi_semicolonthen
localaltform=sub(form,1,i_semicolon-1)
localaltlabels=split(sub(form,i_semicolon+1),"")
insert(forms,concat{
"<span class=\ "Jpan\ "lang=\ ""..lang_code.."\ "style=\ "font-size:140%\ ">[[ ",
altform,
"#"..lang_name.."|",
altform,
"]]</span> <small>",
show_labels{labels=altlabels,lang=lang,nocat=true},
"</small>",
})
else
insert(forms,concat{
"<span class=\ "Jpan\ "lang=\ ""..lang_code.."\ "style=\ "font-size:140%\ ">[[ ",
form,
"#"..lang_name.."|",
form,
"]]</span>"
})
end
end
end
forms_table="\n"..[[{| class= "wikitable floatright"
!style= "font-weight:normal" | Alternative spelling]]..(#forms==1and""or"s")..[[
|-
| style= "text-align:center;font-size:108%" | ]]..concat(forms,"<br>").."\n|} "
end
localforms_table2=""
ifargs.alt2andargs.alt2~=""andargs.alt2~="-"then
localforms2={}
forformingsplit(args.alt2,",")do
insert(forms2,"<span class=\ "Jpan\ "lang=\ ""..lang_code.."\ ">[[ "..form.."#"..lang_name.."|"..form.."]]</span>")
end
forms_table2="\n"..[[{| class= "wikitable floatright"
!style= "font-weight:normal" | Variant form]]..(#forms2==1and""or"s").."\n"..[[
| style= "text-align:center;font-size:140%" | ]]..concat(forms2,"<br>").."\n|} "
end
-- use user-provided sortkey if we got one, otherwise
-- use the sortkey we've already made by combining the
-- readings if provided, if we have neither then
-- default to empty string and don't sort
localsortkey
ifargs.sortthen
sortkey=args.sort
else
sortkey={non_kanji[1]}
localid=1
for_,vinipairs(readings_actual)do
id=id+v[2]
insert(sortkey,(v[1]or"")..(non_kanji[id]or""))
end
sortkey=concat(sortkey)
end
ifsortkey==""then
sortkey=nil
else
sortkey=lang:makeSortKey(sortkey)
end
ifsortkey~=lang:makeSortKey(PAGENAME)then
require("Module:debug/track"){"kanjitab/nonstandard sortkey","kanjitab/nonstandard sortkey/"..lang_code}
end
returnkanji_table..forms_table..forms_table2..m_utilities.format_categories(categories,lang,sortkey)
end
returnexport
Categories:
- Southern Amami Ōshima modules
- Language-specific utility modules
- Japanese modules
- Old Japanese modules
- Kunigami modules
- Kikai modules
- Okinawan modules
- Proto-Ryukyuan modules
- Miyako modules
- Yonaguni modules
- Northern Amami Ōshima modules
- Yaeyama modules
- Hachijō modules
- Proto-Japonic modules
- Tokunoshima modules
- Okinoerabu modules
- Yoron modules