Jump to content

Module:Cs1 documentation support: Difference between revisions

add a code_name_pair_exists function
m (1 revision imported)
(add a code_name_pair_exists function)
Line 1,519: Line 1,519:
end
end


 
--[[--------------------------< C O D E _ N A M E _ P A I R _ E X I S T S >----------------------------------------
 
Returns language code if pair exists, nil if either code doesn't exist or the name doesn't match.
Intended for use by Template:CS1 language sources/core
 
args[1] is language code
args[2] is language name
 
]]
 
local function code_name_pair_exists(frame)
local wiki_language = mw.getContentLanguage():getCode()
local source_list = mw.language.fetchLanguageNames(wiki_language, 'all');
local code_list = {};
local name_list = {};
local override = cfg.lang_tag_remap;
 
for code, name in pairs(source_list) do
add_to_list(code_list, name_list, override, code, name);
end
 
local args = getArgs(frame);
local language_code = args[1]
local language_name = args[2]
-- Check if the language code exists and the corresponding name matches
if code_list[language_code] == language_name then
-- Both code and name are a valid pair
return language_code
else
-- Either code doesn't exist or the name doesn't match
return nil
end
end
 
 
--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
--[[--------------------------< E X P O R T E D  F U N C T I O N S >------------------------------------------
]]
]]
Line 1,529: Line 1,564:
canonical_name_get = canonical_name_get,
canonical_name_get = canonical_name_get,
cat_lister = cat_lister,
cat_lister = cat_lister,
code_name_pair_exists = code_name_pair_exists,
error_cat_page_tally = error_cat_page_tally,
error_cat_page_tally = error_cat_page_tally,
header_make = header_make,
header_make = header_make,
Anonymous user