Module:usex: Difference between revisions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local debug_track_module = "Module:debug/track" | |||
local links_module = "Module:links" | local links_module = "Module:links" | ||
local scripts_module = "Module:scripts" | local scripts_module = "Module:scripts" | ||
| Line 47: | Line 48: | ||
footer = 'e-footer' | footer = 'e-footer' | ||
} | } | ||
-- helper functions | |||
local function track(page, code) | |||
local tracking_page = "usex/" .. page | |||
local debug_track = require(debug_track_module) | |||
debug_track(tracking_page) | |||
if code then | |||
debug_track(tracking_page .. "/" .. code) | |||
end | |||
return true | |||
end | |||
| Line 102: | Line 116: | ||
function export.apply_subst(usex, subst, track) | function export.apply_subst(usex, subst, track) | ||
local subbed_usex = require(links_module).remove_links(usex) | local subbed_usex = require(links_module).remove_links(usex) | ||
local function do_track(page) | |||
if track then | |||
track(page) | |||
end | |||
return true | |||
end | |||
if subst then | if subst then | ||
-- [[Special:WhatLinksHere/Wiktionary:Tracking/usex/subst]] | |||
do_track("subst") | |||
subst = rsplit(subst, ",") | subst = rsplit(subst, ",") | ||
for _, subpair in ipairs(subst) do | for _, subpair in ipairs(subst) do | ||
-- [[Special:WhatLinksHere/Wiktionary:Tracking/usex/subst-single-slash]] | -- [[Special:WhatLinksHere/Wiktionary:Tracking/usex/subst-single-slash]] | ||
local subsplit = rsplit(subpair, rfind(subpair, "//") and "//" or "/") | local subsplit = rsplit(subpair, rfind(subpair, "//") and "//" or do_track("subst-single-slash") and "/") | ||
subbed_usex = rsub(subbed_usex, subsplit[1], subsplit[2]) | subbed_usex = rsub(subbed_usex, subsplit[1], subsplit[2]) | ||
end | end | ||
| Line 190: | Line 212: | ||
else | else | ||
-- Try to auto-transliterate. | -- Try to auto-transliterate. | ||
if | if tr then | ||
-- [[Special:WhatLinksHere/Wiktionary:Tracking/usex/manual-tr]] | |||
-- [[Special:WhatLinksHere/Wiktionary:Tracking/usex/manual-tr/LANGCODE]] | |||
track("manual-tr", langcode) | |||
else | |||
-- First, try transliterating the normalization, if supplied. | -- First, try transliterating the normalization, if supplied. | ||
if norm and normsc | if norm and normsc then | ||
local normsc_code = normsc:getCode() | |||
if normsc_code ~= "None" and not normsc_code:find("Lat") then -- Latn, Latf, Latg, pjt-Latn | |||
local subbed_norm = export.apply_subst(norm, subst, track) | |||
tr = lang:transliterate(subbed_norm, normsc) | |||
end | |||
end | end | ||
-- If no normalization, or the normalization is in a Latin script, or the transliteration of the | -- If no normalization, or the normalization is in a Latin script, or the transliteration of the | ||
-- normalization failed, fall back to transliterating the usex. | -- normalization failed, fall back to transliterating the usex. | ||
if not tr then | if not tr and usex then | ||
local subbed_usex = export.apply_subst(usex, subst, track) | local subbed_usex = export.apply_subst(usex, subst, track) | ||
tr = | tr = lang:transliterate(subbed_usex, sc) | ||
end | end | ||
| Line 217: | Line 246: | ||
-- If there is still no transliteration, then add a cleanup category. | -- If there is still no transliteration, then add a cleanup category. | ||
if not tr and needs_translit[langcode] | if not tr and needs_translit[langcode] then | ||
local sccode = sc:getCode() | |||
if sccode ~= "None" and not sccode:find("Lat") then | |||
table.insert(categories, ("Requests for transliteration of %s %ss"):format(lang:getCanonicalName(), | |||
example_type)) | |||
end | |||
end | end | ||
end | |||
if tr and norm then | |||
track("tr-and-norm") | |||
end | end | ||
if tr then | if tr then | ||
| Line 299: | Line 334: | ||
if ref and ref ~= "" then | if ref and ref ~= "" then | ||
track("ref") | |||
table.insert(result, ref) | table.insert(result, ref) | ||
end | end | ||