Module:usex: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 52: | Line 52: | ||
-- helper functions | -- helper functions | ||
local function track(page) | local function track(page, code) | ||
require(debug_track_module)(" | 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 | return true | ||
end | end | ||
| Line 172: | Line 177: | ||
local usex = data.usex | local usex = data.usex | ||
local sc = data.sc | local sc = data.sc | ||
local sc_explicit = sc | |||
local tr = data.tr | local tr = data.tr | ||
local ts = data.ts | local ts = data.ts | ||
| Line 206: | 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 233: | 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 253: | Line 272: | ||
face = nil | face = nil | ||
else | else | ||
face = " | face = "term" | ||
end | end | ||
| Line 288: | Line 307: | ||
else | else | ||
if tr then | if tr then | ||
table.insert(categories, ("Requests for | table.insert(categories, ("Requests for %s in %s %ss"):format( | ||
sc_explicit and sc_explicit:getDisplayForm() or "native script", | |||
lang:getCanonicalName(), example_type)) | |||
end | end | ||
| Line 324: | Line 344: | ||
norm = norm | norm = norm | ||
} | } | ||
end | |||
local function format_audio(audio) | |||
if audio then | |||
return " [[File:" .. audio .. "|25px]]" | |||
else | |||
return "" | |||
end | |||
end | end | ||
| Line 363: | Line 392: | ||
* `ref`: Reference text to display directly after the right qualifiers. (FIXME: Instead, this should be actual | * `ref`: Reference text to display directly after the right qualifiers. (FIXME: Instead, this should be actual | ||
references.) | references.) | ||
* `audio`: Name of the audio file containing the usex in spoken form. | |||
* `orig`: Original text, if the primary text of the usex or quotation is a translation. | * `orig`: Original text, if the primary text of the usex or quotation is a translation. | ||
* `origlang`: The language object of the original text. Mandatory if original text given. May be an etymology language. | * `origlang`: The language object of the original text. Mandatory if original text given. May be an etymology language. | ||
| Line 401: | Line 431: | ||
local quote = data.quote | local quote = data.quote | ||
local lit = data.lit | local lit = data.lit | ||
local audio = data.audio | |||
local source = data.source | local source = data.source | ||
local brackets = data.brackets | local brackets = data.brackets | ||
| Line 510: | Line 541: | ||
ins(usex_obj.usex) | ins(usex_obj.usex) | ||
ins(format_audio(audio)) | |||
local function insert_annotations(obj) | local function insert_annotations(obj) | ||
| Line 565: | Line 598: | ||
ins(usex_obj.usex) | ins(usex_obj.usex) | ||
ins(format_audio(audio)) | |||
local any_usex_annotations = usex_obj.tr or usex_obj.ts or usex_obj.norm or translation or lit | local any_usex_annotations = usex_obj.tr or usex_obj.ts or usex_obj.norm or translation or lit | ||
local any_orig_annotations = orig_obj and (orig_obj.tr or orig_obj.ts or orig_obj.norm) | local any_orig_annotations = orig_obj and (orig_obj.tr or orig_obj.ts or orig_obj.norm) | ||