Modul:etymology/specialized
Penampilan
- Laman modul ini kekurangan sublaman pendokumenan. Sila cipta laman pendokumenan tersebut.
- Pautan berguna: akar laman • sublaman akar laman • pautan • transklusi • kes ujian • kotak pasir
local export = {}
local m_str_utils = require("Module:string utilities")
local en_utilities_module = "Module:en-utilities"
local etymology_module = "Module:etymology"
local gsub = m_str_utils.gsub
local insert = table.insert
local pluralize = require(en_utilities_module).pluralize
local upper = m_str_utils.upper
-- This function handles all the messiness of different types of specialized borrowings. It should insert any
-- borrowing-type-specific categories into `categories` unless `nocat` is given, and return the text to display
-- before the source + term (or "" for no text).
local function get_specialized_borrowing_text_insert_cats(data)
local bortype, categories, lang, terms, source, nocap, nocat, senseid =
data.bortype, data.categories, data.lang, data.terms, data.source, data.nocap, data.nocat, data.senseid
local function inscat(cat)
if not nocat then
local display, sourcedisp = require(etymology_module).get_display_and_cat_name(source, "raw")
if cat:find("DISPLAY") then
cat = cat:gsub("DISPLAY", display)
elseif cat:find("SOURCE") then
cat = cat:gsub("SOURCE", sourcedisp)
else
cat = cat .. " " .. sourcedisp
end
insert(categories, "Perkataan bahasa " .. lang:getCanonicalName() .. " " .. cat)
end
end
-- `text` is the display text for the borrowing type, which gets converted
-- into a link.
-- `appendix` is a the glossary anchor, which defaults to `text`
-- `prep` is the preposition between the borrowing type and the language
-- name (e.g. "of", "from")
-- `pos` is the part of speech for the borrowing type ("noun" or
-- "kata sifat"; defaults to "noun")
-- `plural` is the plural form of the borrowing type; if not specified,
-- the pluralize function is used
local text, appendix, prep, pos, plural
if bortype == "calque" then
text, prep = "pinjaman terjemah", "bagi"
inscat("dipinjam terjemah daripada bahasa")
elseif bortype == "partial-calque" then
text, prep = "pinjaman terjemah separa", "bagi"
inscat("dipinjam terjemah separa daripada bahasa")
elseif bortype == "semantic-loan" then
text, prep = "pinjaman semantik", "daripada"
inscat("dipinjam secara semantik daripada bahasa")
elseif bortype == "transliteration" then
text, prep = "transliterasi", "bagi"
inscat("dipinjam daripada bahasa")
inscat("transliterasi perkataan DISPLAY")
elseif bortype == "phono-semantic-matching" then
text, prep = "padanan fonosemantik", "bagi"
inscat("dengan padanan fonosemantik daripada bahasa")
else
local langcode = lang:getCode()
local lang_is_source = langcode == source:getCode()
if lang_is_source then
-- Track, because this shouldn't be happening. A language can only have itself as a source further up the chain after a borrowing, which is always "derived".
require("Module:debug/track"){
"etymology/specialized/self-as-source",
"etymology/specialized/self-as-source/" .. langcode
}
inscat("dipinjam balik ke dalam")
else
inscat("dipinjam daripada")
if bortype ~= "borrowing" then
inscat("pinjaman " .. bortype, "daripada")
end
end
if bortype == "borrowing" then
text, appendix, prep, pos = "borrowed", "loanword", "from", "kata sifat"
elseif bortype == "learned" then
text, prep = "pinjaman terpelajar", "daripada"
elseif bortype == "semi-learned" then
text, prep = "pinjaman terpelajar separa", "daripada"
elseif bortype == "orthographic" then
text, prep = "pinjaman ortografik", "daripada"
elseif bortype == "unadapted" then
text, prep = "pinjaman tidak tersuai", "daripada"
elseif bortype == "adapted" then
text, prep = "pinjaman " .. bortype, "daripada"
else
error("Internal error: Unrecognized bortype: " .. bortype)
end
if bortype == "borrowing" then
text, appendix, prep, pos = "borrowed", "loanword", "from", "kata sifat"
elseif bortype == "learned" then
text, prep = "pinjaman terpelajar", "daripada"
elseif bortype == "semi-learned" then
text, prep = "pinjaman terpelajar separa", "daripada"
elseif bortype == "orthographic" then
text, prep = "pinjaman ortografik", "daripada"
elseif bortype == "unadapted" then
text, prep = "pinjaman tidak tersuai", "daripada"
elseif bortype == "adapted" then
text, prep = "pinjaman " .. bortype, "daripada"
else
error("Internal error: Unrecognized bortype: " .. bortype)
end
end
-- If the term is suppressed, the preposition should always be "from":
-- "Calque of Chinese 中國".
-- "Calque from Chinese" (not "Calque of Chinese").
if terms[1].term == "-" then
prep = "daripada"
end
appendix = "Lampiran:Glosari#" .. (appendix or text)
if senseid then
local senseids, output = mw.text.split(senseid, '!!'), {}
for i, id in ipairs(senseids) do
-- FIXME: This should be done via a function.
insert(output, mw.getCurrentFrame():preprocess('{{senseno|' .. lang:getCode() .. '|' .. id .. (i == 1 and not nocap and "|uc=1" or "") .. '}}'))
end
local link
if senseid:find('!!') then
link, text = "merupakan", pos == "kata sifat" and text or plural or pluralize(text)
else
link = pos == "kata sifat" and "merupakan" or "merupakan"
end
text = mw.text.listToText(output) .. " " .. link .. " " .. '[[' .. appendix .. '|' .. text .. ']]'
else
text = "[[" .. appendix .. "|" .. (nocap and text or gsub(text, "^.", upper)) .. "]]"
end
return text .. " " .. prep .. " "
end
function export.specialized_borrowing(data)
local lang, sources, terms = data.lang, data.sources, data.terms
local categories = {}
local text
for _, source in ipairs(sources) do
text = get_specialized_borrowing_text_insert_cats {
bortype = data.bortype,
categories = categories,
lang = lang,
terms = terms,
source = source,
nocap = data.nocap,
nocat = data.nocat,
senseid = data.senseid,
}
end
text = data.notext and "" or text
return text .. require(etymology_module).format_sources {
lang = lang,
sources = sources,
terms = terms,
sort_key = data.sort_key,
categories = categories,
nocat = data.nocat,
sourceconj = data.sourceconj,
} .. require(etymology_module).format_links(terms, data.conj, "etymology/specialized")
end
return export