Module:Sandbox/Certes: Difference between revisions
Appearance
Content deleted Content added
Sync from Module:Lang |
Allow link= syntax in language list |
||
Line 2: | Line 2: | ||
local subtags = {}; -- IETF subtags script, region, variant, and private |
local subtags = {}; -- IETF subtags script, region, variant, and private |
||
local raw_code = frame.args[1]; -- save a copy of the input IETF subtag |
local raw_code = frame.args[1]; -- save a copy of the input IETF subtag |
||
local link = 'yes' == frame.args['link']; -- save a copy of the link-enable positional parameter (value can be anything) |
local link = 'yes' == frame.args['link']; -- save a copy of the link-enable positional parameter (value can be anything) |
||
local code; -- the language code |
local code; -- the language code |
||
local msg; -- gets an error message if IETF language tag is malformed or invalid |
local msg; -- gets an error message if IETF language tag is malformed or invalid |
||
local |
local language_list = {''}; |
||
local language_name; |
|||
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code); |
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code); |
||
Line 14: | Line 15: | ||
if lang_data.override[raw_code:lower()] then -- look for whole IETF tag in override table (force lower case) |
if lang_data.override[raw_code:lower()] then -- look for whole IETF tag in override table (force lower case) |
||
language_list = lang_data.override[raw_code:lower()]; |
|||
elseif lang_data.override[code] then -- not there so try basic language code in override table |
elseif lang_data.override[code] then -- not there so try basic language code in override table |
||
language_list = lang_data.override[code]; |
|||
elseif not is_set (subtags.variant) then |
elseif not is_set (subtags.variant) then |
||
if lang_name_table.lang[code] then |
if lang_name_table.lang[code] then |
||
language_list = lang_name_table.lang[code]; |
|||
end |
end |
||
else -- TODO: is this the right thing to do: take language display name from variants table? |
else -- TODO: is this the right thing to do: take language display name from variants table? |
||
if lang_name_table.variant[subtags.variant] then -- TODO: there is some discussion at Template talk:Lang about having a label parameter for use when variant name is not desired among other things |
if lang_name_table.variant[subtags.variant] then -- TODO: there is some discussion at Template talk:Lang about having a label parameter for use when variant name is not desired among other things |
||
language_list = lang_name_table.variant[subtags.variant]['descriptions']; -- table entries sometimes have multiple names, always take the first one |
|||
end |
end |
||
end |
end |
||
language_name = language_list[1]; -- table entries sometimes have multiple names, always take the first one |
|||
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them |
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them |
||
if link then -- when |link=yes, wikilink the language name |
if link then -- when |link=yes, wikilink the language name |
||
if |
if language_list["link"] then |
||
return make_wikilink (language_list["link"], language_name); -- explicit wikilink given with link= syntax |
|||
elseif language_name:find ('languages') then |
|||
return make_wikilink (language_name); -- collective language name uses simple wikilink |
return make_wikilink (language_name); -- collective language name uses simple wikilink |
||
else |
else |
Revision as of 17:40, 9 December 2018
local function name_from_code (frame)
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = frame.args[1]; -- save a copy of the input IETF subtag
local link = 'yes' == frame.args['link']; -- save a copy of the link-enable positional parameter (value can be anything)
local code; -- the language code
local msg; -- gets an error message if IETF language tag is malformed or invalid
local language_list = {''};
local language_name;
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code);
if msg then
local template = (frame.args['template'] and table.concat ({'{{', frame.args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: ', template, msg, '</span>'});
end
if lang_data.override[raw_code:lower()] then -- look for whole IETF tag in override table (force lower case)
language_list = lang_data.override[raw_code:lower()];
elseif lang_data.override[code] then -- not there so try basic language code in override table
language_list = lang_data.override[code];
elseif not is_set (subtags.variant) then
if lang_name_table.lang[code] then
language_list = lang_name_table.lang[code];
end
else -- TODO: is this the right thing to do: take language display name from variants table?
if lang_name_table.variant[subtags.variant] then -- TODO: there is some discussion at Template talk:Lang about having a label parameter for use when variant name is not desired among other things
language_list = lang_name_table.variant[subtags.variant]['descriptions']; -- table entries sometimes have multiple names, always take the first one
end
end
language_name = language_list[1]; -- table entries sometimes have multiple names, always take the first one
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them
if link then -- when |link=yes, wikilink the language name
if language_list["link"] then
return make_wikilink (language_list["link"], language_name); -- explicit wikilink given with link= syntax
elseif language_name:find ('languages') then
return make_wikilink (language_name); -- collective language name uses simple wikilink
else
return make_wikilink (language_name .. ' language', language_name); -- language name with wikilink
end
end
return language_name;
end