Module:Lang: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary |
No edit summary |
||
Line 31: | Line 31: | ||
local function is_set( var ) |
local function is_set( var ) |
||
return not (var == nil or var == ''); |
return not (var == nil or var == ''); |
||
⚫ | |||
--[[--------------------------< 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 |
end |
||
Line 322: | Line 351: | ||
--[[--------------------------< M A K E _ T E X T _ S P A N >-------------------------------------------------- |
--[[--------------------------< 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 |
TODO: add support for block: div tags instead of span tags; would need some sort of proper parameter to control the switch |
||
Line 337: | Line 364: | ||
table.insert (span, ' dir="rtl"'); -- for right to left languages |
table.insert (span, ' dir="rtl"'); -- for right to left languages |
||
end |
end |
||
⚫ | |||
table.insert (span, table.concat ({' style=\"font-style:', italic})); -- TODO: rename italic to style as that is more meaningful |
|||
⚫ | |||
if is_set (size) then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
table.insert (span, '\">'); -- close the style and close opening span tag |
|||
table.insert (span, text); -- insert the text |
|||
⚫ | |||
-- table.insert (span, table.concat ({' style="font-size:', size, ';"'})) |
|||
-- end |
|||
⚫ | |||
⚫ | |||
-- table.insert (span, table.concat ({"''", text, "''"})); -- text with italic markup |
|||
⚫ | |||
⚫ | |||
-- end |
|||
table.insert (span, '</span>'); -- close the span |
table.insert (span, '</span>'); -- close the span |
||
if rtl then |
if rtl then |
||
Line 712: | Line 748: | ||
end |
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 |
-- 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 |
-- 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 |
else |
||
args.italic = |
args.italic = initial_style_state; -- here when |italic= and |script= not set; set for font-style:<initial_style_state> |
||
end |
end |
||
end |
end |