Module:pron qualifier: Difference between revisions
Created page with "local export = {} local labels_module = "Module:labels" local qualifier_module = "Module:qualifier" local references_module = "Module:references" local function track(page) require("Module:debug/track")("pron qualifier/" .. page) return true end --[==[ This function is used by any module that wants to add support for (some subset of) left and right regular and accent qualifiers, labels and references to a template that specifies a pronunciation or related property...." |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- TODO: this module is now used for more than just pronunciations and should be renamed. | |||
local export = {} | local export = {} | ||
| Line 12: | Line 13: | ||
--[==[ | --[==[ | ||
This function is used by any module that wants to add support for (some subset of) left and right regular and accent | This function is used by any module that wants to add support for (some subset of) left and right regular and accent | ||
qualifiers, labels and references to a template | qualifiers, labels and references to a template, e.g. for pronunciations. | ||
by [[Module:IPA]], [[Module:rhymes]], [[Module:hyphenation]], [[Module:homophones]] and various lang-specific modules | |||
such as [[Module:es-pronunc]] (for specifying pronunciation, rhymes, hyphenation, homophones and audio in {{tl|es-pr}}).It should potentially also be used in {{tl|audio}}. To reduce memory usage, the caller should check that any qualifiers | It is currently used by [[Module:IPA]], [[Module:rhymes]], [[Module:hyphenation]], [[Module:homophones]], | ||
exist before loading the module. | [[Module:affix]] and various lang-specific modules such as [[Module:es-pronunc]] (for specifying pronunciation, | ||
rhymes, hyphenation, homophones and audio in {{tl|es-pr}}). It should potentially also be used in {{tl|audio}}. | |||
To reduce memory usage, the caller should check that any qualifiers exist before loading the module. | |||
`data` is a structure containing the following fields: | `data` is a structure containing the following fields: | ||
| Line 38: | Line 42: | ||
* `lang`: Language object for accent qualifiers. | * `lang`: Language object for accent qualifiers. | ||
* `text`: The text to wrap with qualifiers. | * `text`: The text to wrap with qualifiers. | ||
*` raw`: Don't do any CSS wrapping of the formatted text. | |||
The order of qualifiers and labels, on both the left and right, is (1) labels, (2) accent qualifiers, (3) regular | The order of qualifiers and labels, on both the left and right, is (1) labels, (2) accent qualifiers, (3) regular | ||
| Line 75: | Line 80: | ||
no_ib_content = true, | no_ib_content = true, | ||
no_track_already_seen = true, | no_track_already_seen = true, | ||
ok_to_destructively_modify = true, -- doesn't apply to `labels` | |||
raw = data.raw, | |||
} | } | ||
end | end | ||
| Line 85: | Line 92: | ||
end | end | ||
if has_qualifiers then | if has_qualifiers then | ||
ins(m_qualifier.format_qualifiers | ins(m_qualifier.format_qualifiers { | ||
qualifiers = qualifiers, | |||
open = false, | |||
close = false, | |||
no_ib_content = true, | |||
raw = data.raw, | |||
}) | |||
end | end | ||
local qualifier_inside | local qualifier_inside | ||
local function wrap_qualifier_css(txt, suffix) | |||
if data.raw then | |||
return txt | |||
else | |||
return m_qualifier.wrap_qualifier_css(txt, suffix) | |||
end | |||
end | |||
if qualifier_like_parts[2] then | if qualifier_like_parts[2] then | ||
qualifier_inside = table.concat(qualifier_like_parts, | qualifier_inside = table.concat(qualifier_like_parts, wrap_qualifier_css(",", "comma") .. " ") | ||
else | else | ||
qualifier_inside = qualifier_like_parts[1] | qualifier_inside = qualifier_like_parts[1] | ||
end | end | ||
qualifier_like_parts = {} | qualifier_like_parts = {} | ||
ins( | ins(wrap_qualifier_css("(", "brac")) | ||
ins( | ins(wrap_qualifier_css(qualifier_inside, "content")) | ||
ins( | ins(wrap_qualifier_css(")", "brac")) | ||
return table.concat(qualifier_like_parts) | return table.concat(qualifier_like_parts) | ||
end | end | ||