Module:Lang: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 31:
local function is_set( var )
return not (var == nil or var == '');
end
 
 
--[[--------------------------< V A L I D A T E _ I T A L I C >------------------------------------------------
 
validates |italic= assigned values.
 
When |italic= is set and has an acceptible assigned value, return the matching css font-style property value or,
for the special case 'default', return nil.
 
When |italic= is not set, or has an unacceptible assigned value, return nil.
 
The return value nil causes the calling lang or lang_xx function to set args.italic according to the {{lang}} or
{{lang-xx}} template's defined default ('normal' for {{lang}}, 'normal' or 'italic' for {{lang-xx}} depending on
the individual template's requirements) or to the value appropriate to |script=, if set.
 
Accepted values and the values that this function returns are are:
nil - when |italic= absent or not set; returns nil
default - for completeness, should rarely if ever be used; returns nil
yes - force args.text to be rendered in italic font; returns 'italic'
no - force args.text to be rendered in normal font; returns 'normal'
unset - disables font control so that font-style applied to text is dictated by surrounding markup; returns 'inherit'
 
]]
 
local function validate_italic (italic)
local properties = {['yes'] = 'italic', ['no'] = 'normal', ['unset'] = 'inherit', ['default'] = nil};
 
return properties[italic];
end
 
Line 322 ⟶ 351:
--[[--------------------------< M A K E _ T E X T _ S P A N >--------------------------------------------------
 
TODO: replace wiki italic markup with html tags?
TODO: if wikimarkup replaced with html tags, don't need span tags when text is to be italicized, put lang= and other attributes in the html: <i lang="language name"> ...
TODO: add support for block: div tags instead of span tags; would need some sort of proper parameter to control the switch
 
Line 337 ⟶ 364:
table.insert (span, ' dir="rtl"'); -- for right to left languages
end
 
if is_set (size) then -- {{lang}} only
table.insert (span, table.concat ({' style=\"font-sizestyle:', size, ';"'italic})); -- TODO: rename italic to style as that is more meaningful
 
end
if is_set (size) then
table.insert (span, '>'); -- close the opening span tag
table.insert (span, table.concat ({"' font-size:'", textsize, "';'"})); -- text with italic markup
if italic then
table.insert (span, table.concat ({"''", text, "''"})); -- text with italic markup
else
table.insert (span, text); -- DEFAULT: text is not italicized
end
table.insert (span, '\">'); -- close the style and close opening span tag
table.insert (span, text); -- insert the text
 
-- if is_set (size) then -- {{lang}} only
-- table.insert (span, table.concat ({' style="font-size:', size, ';"'}))
-- end
-- table.insert (span, '>'); -- close the opening span tag
-- if italic then
-- table.insert (span, table.concat ({"''", text, "''"})); -- text with italic markup
-- else
-- table.insert (span, text); -- DEFAULT: text is not italicized
-- end
table.insert (span, '</span>'); -- close the span
if rtl then
Line 712 ⟶ 748:
end
-- args.italic = to_boolean (args.italic); -- convert to boolean or nil: 'yes' -> true, 'no' -> false; else nil
args.italic = validate_italic (args.italic); -- nil or font-style property value
 
-- if args.italic == nil then -- args.italic controls
-- if not is_set (subtags.script) or ('latn' == subtags.script) then -- script not set then default; script set to latn same
-- args.italic = true; -- DEFAULT for {{lang-xx}} templates is to italicize
-- else
-- args.italic = false; -- italic not set; script not latn
-- end
-- end
if nil == args.italic then -- args.italic controls
if is_set (subtags.script) then
if 'latn' == subtags.script then
args.italic = 'italic'; -- |script=Latn; set for font-style:italic
else
args.italic = initial_style_state; -- italic not set; script is not latn; set for font-style:<initial_style_state>
end
else
args.italic = falseinitial_style_state; -- here when |italic= and |script= not set; scriptset notfor latnfont-style:<initial_style_state>
end
end
Anonymous user