پودمان:Lang/documentor tool
پرش به ناوبری
پرش به جستجو
توضیحات این پودمان میتواند در پودمان:Lang/documentor tool/توضیحات قرار گیرد.
require('Module:No globals')
local p = {}
--[[ -------------------------< P R I V A T E _ T A G S >------------------------------------------------------
{{#invoke:Lang/documentor tool|private_tags}}
Reads the override{} table in Module:Lang/data and renders a wiki table of private tags and their associated languages
]]
local function private_tags (frame)
local override_t = mw.loadData ('Module:Lang/data').override; -- get the override table
local private_t = {};
for tag, lang in pairs (override_t) do
if tag:find ('%-x%-') then
table.insert (private_t, table.concat ({'\n|-\n|', lang[1], '||', tag}))
end
end
table.sort (private_t)
table.insert (private_t, 1, '{| class="wikitable"');
table.insert (private_t, 2, '\n|+ Supported private-use IETF language tags')
table.insert (private_t, 3, '\n! Language !! Private-use tag')
return table.concat (private_t) .. '\n|}';
-- return '<pre>' .. table.concat (private_t) .. '\n|}' .. '</pre>'
--error (mw.dumpObject (private_t))
end
--[[ -------------------------< L A N G - X X _ S E T T I N G S >----------------------------------------------
{{#invoke:Lang/documentor tool|lang_xx_settings|template={{ROOTPAGENAME}}}}
Reads the content of the template and extracts the parameters from {{#invoke:Lang|...}} for display on the template's
documentation page.
]]
local function lang_xx_settings(frame)
local page = mw.title.makeTitle('الگو', frame.args['template'] or frame.args[1] or frame.args['الگو']) -- get a page object for this page in 'Template:' namespace
if not page then
return '' -- TODO: error message?
end
local content = page:getContent() -- get unparsed content
if not page then
return '' -- TODO: error message?
end
local out = {}
local params
local style
if content:match('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+|[^}]+}}') or content:match('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+|[^}]+}}') then -- if this template uses [[Module:Lang]]
params = content:match('{{%s*#invoke:%s*[Ll]ang%s*|[^|]+(|[^}]+)}}') or content:match('{{%s*#invoke:%s*[Ll]ang/sandbox%s*|[^|]+(|[^}]+)}}') -- extract the #invoke:'s parameters
if not params then
return '' -- there should be at least one or the template/module won't work TODO: error message?
end
table.insert(out, '{| class="wikitable" style="text-align: left; float: left;"\n|+settings') -- start a wikitable
for k, v in params:gmatch('%s*|%s*([^%s=]+)%s*=%s*([^%s|]+)') do -- get the parameter names (k) and values (v)
if 'label' == k then -- special case for labels because spaces and pipes
v = params:match('label%s*=%s*(%[%[[^%]]+%]%])') or params:match('label%s*=%s*([^|\n]+)') or 'missing label'
end
table.insert(out, table.concat({k, '\n|', v})) -- make rudimentary wikitable entries
end
style = content:match('lang_xx_([^|]+)')
return table.concat({table.concat(out,'\n|-\n! scope="row" | '), '\n|-\n|colspan="2"|style: ', style, '\n|-\n|}'}) -- add inter-row markup and close the wikitable and done
else
return '' -- does not use [[Module:Lang]] so abandon quietly
end
end
--[[ -------------------------- < U S E S _ M O D U L E > --------------------------
{{#invoke:Lang/documentor tool|uses_module|template={{ROOTPAGENAME}}}}
Reads the content of the template to determine if this {{lang-xx}} template uses Module:Lang.
Returns the index of the substring '{{#invoke|lang|' in the template page content if true; empty string if false.
Used in template documentation {{#if:}} parser functions.
]]
local function uses_module(frame)
local page = mw.title.makeTitle('الگو', frame.args['template'] or frame.args[1] or frame.args['الگو']) -- get a page object for this page in 'Template:' namespace
if not page then
return '' -- TODO: error message?
end
local content = page:getContent() -- get unparsed content
if not page then
return '' -- TODO: error message?
end
return content:find('{{%s*#invoke:[Ll]ang%s*|') or '' -- return index or empty string
end
--[[ -------------------------- < S H A R E D _ C O D E > --------------------------
- Tables:
-- language_categories
-- error_messages
-- strings
- Functions:
-- make_error(message, layout, parent_category, nocat)
-- get_language_link(language_name, language_code)
-- get_see_also_section(page_title, language_name, language_code)
-- get_hidden_category_template(frame)
-- get_top_section(frame)
-- get_bottom_section(frame, language_name, see_also_section, parent_category)
]]
local language_categories = {
["LANGUAGES_SOURCES"] = "مقالههای دارای منابع به زبان %s (%s)",
["LANGUAGES_COLLECTIVE_SOURCES"] = "مقالههای دارای منابع به %s جمعی (%s)",
["CS1"] = "یادکردهای دارای منبع به زبان %s",
["LANGUAGE_TEXT"] = "مقالههای دارای واژگان به زبان %s",
-- old version ["LANGUAGES_COLLECTIVE_TEXT"] = "Articles with text from the %s collective",
["LANGUAGES_COLLECTIVE_TEXT"] = "مقالههای دارای واژگان به %s", -- متن به «زبانهای فلان» که یک مجموعه زبان مشترک است
["PERSIAN"] = "مقالههای دارای ارجاع صریح به متن به زبان %s",
}
local error_assistance = " لطفاً برای اطلاعات بیشتر [[بحث الگو:Lang]] را ببینید."
local error_messages = {
["ASSISTANCE"] = "برای اطلاعات بیشتر، [[بحث الگو:Lang]] را ببینید.",
["INCORRECT_CATEGORY_TITLE"] = "[[:%s]] ردهای نیست که توسط الگوی {{tlx|%s}} پر شود. ردهٔ صحیح در اینجا قرار دارد: [[:%s]].",
["NO_CATEGORY_TITLE_FOUND"] = "هیچ ردهٔ زبانی برای زبان '''%s.''' یافت نشد" .. error_assistance,
["NOT_VALID_CATEGORY_FORMAT"] = "عنوان ردهٔ '''%s''' نامعتبر است." .. error_assistance,
["NOT_VALID_LANGUAGE_CODE"] = "[[%s]] نام زبان ISO 639 یا IETF نامعتبر است." .. error_assistance,
}
local strings = {
["ERROR_CATEGORY"] = "[[رده:خطاهای الگوهای زبان]]",
["ERROR_SPAN"] = '<span style="font-size: 100%%; font-style: normal;" class="error">خطا: %s </span>',
["PURGE_DIV"] = '<div style="font-size: x-small;">%s</div>',
["SEE_ALSO"] = "\n== جستارهای وابسته ==",
["SEE_ALSO_ITEM"] = "* [[:%s]]",
}
--[[ -------------------------- < M A K E _ E R R O R > --------------------------
Create an error message.
Does not place page in error category if args.nocat is used.
Does not categorize in parent cateogory if used in category namespace (usually for /testcases).
]]
local function make_error(message, layout, parent_category, nocat)
table.insert(layout, string.format(strings["ERROR_SPAN"], message))
if not nocat then
table.insert(layout, strings["ERROR_CATEGORY"])
end
if mw.title.getCurrentTitle().nsText == "رده" then
table.insert(layout, parent_category)
end
return table.concat(layout)
end
--[[ -------------------------- < G E T _ L A N G U A G E _ L I N K > --------------------------
Generates a language link for the correct style.
Collective languages use the name_from_tag value,
while other languages use a display name of "x-language".
]]
local function get_language_link(language_name, language_code)
local lang_module = require('Module:Lang')
-- Is a language collective?
if mw.ustring.find(language_name, 'زبانهای') then
return lang_module.name_from_tag({language_code, link = "yes"})
else
return lang_module.name_from_tag({language_code, link = "yes", label = "زبان " .. lang_module.name_from_tag({language_code})})
end
end
--[[ -------------------------- < G E T _ S E E _ A L S O _ S E C T I O N > --------------------------
Generates a consistent style See also section for
{{Category articles containing non-English-language text}} and {{Non-English-language source category}}.
If {{CS1 language sources}} is converted, it should also use it.
]]
local function get_see_also_section(page_title, language_name, language_code)
local see_also_section = {}
for _, category_name in pairs(language_categories) do
local category = mw.title.new(string.format(category_name, language_name, language_code), 14)
if category and page_title ~= category.text and category.exists then
table.insert(see_also_section, string.format(strings["SEE_ALSO_ITEM"], category.prefixedText))
end
end
table.sort(see_also_section)
table.insert(see_also_section, 1, strings["SEE_ALSO"])
if table.getn(see_also_section) == 1 then
return ""
else
return table.concat(see_also_section, "\n")
end
end
--[[ -------------------------- < G E T _ H I D D E N _ C A T E G O R Y _ T E M P L A T E > --------------------------
Generates the Template:Hidden category template.
This function is separate from the get_top_section() function
as this should be used in both error categories and valid categories.
]]
local function get_hidden_category_template(frame)
return frame:expandTemplate{title = 'Hidden category'}
end
--[[ -------------------------- < G E T _ T O P _ S E C T I O N > --------------------------
Generates a consistent top maintenance template section which consists of:
-- Template:Possibly empty category
-- Template:Purge
]]
local function get_top_section(frame)
local top_section = {}
if mw.site.stats.pagesInCategory(mw.title.getCurrentTitle().text, "all") == 0 then
table.insert(top_section, frame:expandTemplate{title = 'رده خالی'})
else
table.insert(top_section, frame:expandTemplate{title = 'رده خالی', args = {hidden=true}})
end
local purge_module = require('Module:Purge')
table.insert(top_section, string.format(strings["PURGE_DIV"], purge_module._main({"خالی کردن میانگیر این صفحه"})))
return table.concat(top_section, "\n\n")
end
--[[ -------------------------- < G E T _ B O T T O M _ S E C T I O N > --------------------------
Generates a consistent non-text section which consists of:
-- Template:CatAutoTOC
-- A see also section
-- {{DEFAULTSORT}}
-- Categorization in parent category
]]
local function get_bottom_section(frame, language_name, see_also_section, parent_category)
local bottom_section = {}
table.insert(bottom_section, frame:expandTemplate{title = 'CatAutoTOC'})
table.insert(bottom_section, see_also_section)
if mw.title.getCurrentTitle().nsText == "رده" then
table.insert(bottom_section, frame:preprocess{text = "{{DEFAULTSORT:" .. language_name .. "}}"})
table.insert(bottom_section, parent_category)
end
return table.concat(bottom_section, "\n\n\n")
end
--[[ -------------------------- < N O N _ E N G L I S H _ L A N G U A G E _ T E X T _ C A T E G O R Y > --------------------------
{{#invoke:Lang/documentor tool|non_english_language_text_category}}
This function implements {{Non-English-language text category}}.
]]
local non_english_language_text_strings = {
["LINE1"] = "این رده دربردارندهٔ مقالههای دارای متن به %s%s است. کاربرد اصلی این ردهها برای تسهیل بررسی دستی یا خودکار متن به زبانهای دیگر است.",
["LINE2"] = "این رده تنها باید با استفاده از الگوهای خانواده %s به صفحههای افزوده شود و هرگز نباید آن را بهطور مستقیم به صفحهها افزود.",
["LINE3"] = 'برای مثال %s که متن را در برچسب <code><span lang="%s"></code> بستهبندی میکند.%s',
["LINE3_EXTRA"] = " نمونه در دسترس دیگر، %s است که خروجی آن به شکل «%s» است.",
["IN_SCRIPT"] = " (به %s)",
["EXAMPLE_DEFAULT_TEXT"] = "متن به زبان %s در اینجا",
["PARENT_CATEGORY"] = "[[رده:صفحههای دارای محتوای غیر فارسی]]",
["TEMPLATE"] = "Lang",
["LANG"] = "Text about LANG, I don't know what to put here yet!"
}
local function non_english_language_text_category(frame)
local page = mw.title.getCurrentTitle()
local args = require('Module:Arguments').getArgs(frame)
-- args.test is used for /testcases
if args.test then
page = mw.title.new(args.test)
end
-- Naming style: Articles with text from the Berber languages collective
local page_title_modified = page.text
local split_title = "^(.+)%%s$"
local part1 = ""
-- local part2 = "" Not needed in fawiki cat titles since language name is always located at the end of the page name
if mw.ustring.find(page_title_modified, 'زبانهای', 1, true) then
-- Naming style: Category:Articles with text from Afro-Asiatic languages (as currently implemented in Module:lang)
part1 = mw.ustring.match(language_categories["LANGUAGES_COLLECTIVE_TEXT"], split_title)
elseif mw.ustring.find(page_title_modified, 'ارجاع صریح', 1, true) then
part1 = mw.ustring.match(language_categories["PERSIAN"], split_title)
else
-- Naming style: Category:Articles containing French-language text
part1 = mw.ustring.match(language_categories["LANGUAGE_TEXT"], split_title)
end
page_title_modified = mw.ustring.gsub(page_title_modified, part1, "")
-- page_title_modified = mw.ustring.gsub(page_title_modified, part2, "")
local language_name = page_title_modified
local layout = {}
table.insert(layout, get_hidden_category_template(frame))
local parent_category = non_english_language_text_strings["PARENT_CATEGORY"]
if language_name == page.text then
-- Error: Category title format not supported.
return make_error(string.format(error_messages["NOT_VALID_CATEGORY_FORMAT"], page.text), layout, parent_category, args.nocat)
end
local lang_module = require('Module:Lang')
local language_code = lang_module._tag_from_name({language_name})
if mw.ustring.find(language_code, 'error') then
-- Error: Language code not found in database.
return make_error(mw.ustring.format(error_messages["NOT_VALID_LANGUAGE_CODE"], language_name), layout, parent_category, args.nocat)
end
local correct_language_category_title = lang_module._category_from_tag({language_code})
if mw.ustring.find(correct_language_category_title, 'خطاهای') then
-- Error: No category title found for language code.
return make_error(mw.ustring.format(error_messages["NO_CATEGORY_TITLE_FOUND"], language_code), layout, parent_category, args.nocat)
end
local current_category_title = page.prefixedText
if current_category_title ~= correct_language_category_title then
-- Error: The current title used is not in the supported format. TODO: can this still be reached?
return make_error(
string.format(error_messages["INCORRECT_CATEGORY_TITLE"], current_category_title, non_english_language_text_strings["LANG"], correct_language_category_title),
layout, parent_category, args.nocat)
end
table.insert(layout, get_top_section(frame))
local script_text = ""
if args.script then
script_text = string.format(non_english_language_text_strings["IN_SCRIPT"], args.script)
end
local language_link = get_language_link(language_name, language_code)
table.insert(layout, string.format(non_english_language_text_strings["LINE1"], script_text, language_link))
local lang_template = frame:expandTemplate{title = 'الگو', args = {non_english_language_text_strings["TEMPLATE"]}} -- الگوی tl که در ویکیپدیای فارسی «الگو» است
table.insert(layout, string.format(non_english_language_text_strings["LINE2"], lang_template))
local language_code_link = lang_module._name_from_tag({language_code, link="yes", label=language_code})
local example_default_text = string.format(non_english_language_text_strings["EXAMPLE_DEFAULT_TEXT"], language_name)
local example_text = args.example or args['نمونه'] or example_default_text
local lang_template_example = frame:expandTemplate{title = 'الگوب', args = {non_english_language_text_strings["TEMPLATE"], language_code_link, example_text}}
local lang_x = mw.title.makeTitle(10, "Lang-" .. language_code)
local line3_extra = ""
if lang_x.exists then
local lang_x_template_example = frame:expandTemplate{title = 'الگوب', args = {lang_x.text, example_text}}
local lang_x_template = frame:expandTemplate{title = lang_x.text, args = {example_text}}
line3_extra = string.format(non_english_language_text_strings["LINE3_EXTRA"], lang_x_template_example, lang_x_template)
end
table.insert(layout, string.format(non_english_language_text_strings["LINE3"], lang_template_example, language_code, line3_extra))
local see_also_section = get_see_also_section(page.text, language_name, language_code)
local bottom = get_bottom_section(frame, language_name, see_also_section, non_english_language_text_strings["PARENT_CATEGORY"])
return table.concat(layout, "\n\n") .. bottom
end
--[[ -------------------------- < N O N _ E N G L I S H _ L A N G U A G E _ S O U R C E S _ C A T E G O R Y > --------------------------
{{#invoke:Lang/documentor tool|non_english_language_sources_category}}
This function implements {{Non-English-language sources category}}.
]]
local non_english_language_sources_strings = {
["LINE1"] = "این یک رده ردیابی است برای یافتن صفحههایی که از %s برای شناسایی منابع %s استفاده میکنند.",
["PARENT_CATEGORY"] = "[[رده:صفحههای دارای محتوای غیر فارسی]]",
["TEMPLATE"] = "In lang",
}
local function non_english_language_sources_category(frame)
local page = mw.title.getCurrentTitle()
local args = require('Module:Arguments').getArgs(frame)
-- args.test is used for /testcases
if args.test or args['آزمایشی'] then
page = mw.title.new(args.test or args['آزمایشی'])
end
local page_title = page.text
local language_code = page_title:match('%(([%a%-]+)%)')
local language_name = require('Module:Lang')._name_from_tag({language_code})
local layout = {}
table.insert(layout, get_hidden_category_template(frame))
local parent_category = non_english_language_sources_strings["PARENT_CATEGORY"]
local correct_language_category_title = require('Module:In lang')._in_lang({language_code, ["list-cats"]="yes"})
if correct_language_category_title == "" then
-- Error: No category title found for language code.
return make_error(string.format(error_messages["NO_CATEGORY_TITLE_FOUND"], language_code), layout, parent_category, args.nocat or args['بیرده'])
end
local current_category_title = page.prefixedText
if correct_language_category_title ~= current_category_title then
-- Error: The current title used is not in the supported format.
return make_error(
string.format(error_messages["INCORRECT_CATEGORY_TITLE"], current_category_title, non_english_language_sources_strings["TEMPLATE"], correct_language_category_title),
layout, parent_category, args.nocat or args['بیرده'])
end
local language_link = get_language_link(language_name, language_code)
local text = string.format(non_english_language_sources_strings["LINE1"], frame:expandTemplate{title = 'Tlx', args = {non_english_language_sources_strings["TEMPLATE"], language_code}}, language_link)
table.insert(layout, get_top_section(frame))
table.insert(layout, text)
local see_also_section = get_see_also_section(page_title, language_name, language_code)
local bottom = get_bottom_section(frame, language_name, see_also_section, parent_category)
return table.concat(layout, "\n\n") .. bottom
end
--[[ -------------------------- < N O N _ E N G L I S H _ L A N G U A G E _ C S 1 _ S O U R C E S _ C A T E G O R Y > --------------------------
{{#invoke:Lang/documentor tool|non_english_language_cs1_sources_category}}
This function implements {{Non-English-language CS1 sources category}}.
]]
local non_english_language_cs1_text_strings = {
["LINE1"] = "این یک رده ردیابی برای [[راهنما:شیوه یادکرد ۱|یادکردهای شیوه ۱]] است که از پارامتر %s برای شناساندن منابع به زبان [[زبان %s|%s]] استفاده میکنند. صفحهها تنها باید با استفاده از الگوهای CS1 و [[پودمان:Citation/CS1]] به این رده افزوده شوند.",
["PARENT_CATEGORY"] = "[[رده:دارای منبع به زبان خارجی]]", -- #TODO change to "Articles with non-english CS1 language sources" or "CS1 non-English language sources"
}
--"This is a tracking category for [[WP:CS1|CS1 citations]] that use the parameter %s to hold a citation title that uses %s characters and contains the language prefix <code>%s:</code>. Pages in this category should only be added by CS1 templates and [[Module:Citation/CS1]].",
--"[[Category:CS1 uses foreign language script]]",
-- "This is a tracking category for [[WP:CS1|CS1 citations]] that use the parameter %s. Pages in this category should only be added by CS1 templates and [[Module:Citation/CS1]].",
-- "to identify a source in [[%s language|%s]].",
-- "to hold a citation title that uses %s characters and contains the language prefix <code>%s:</code>.",
local function non_english_language_cs1_sources_category(frame)
local page_title_object = mw.title.getCurrentTitle()
local page_title = page_title_object.text
local language_code = page_title:match('%(([%a%-]+)%)')
local language_name = require('Module:Lang')._name_from_tag({language_code})
local layout = {}
table.insert(layout, get_hidden_category_template(frame))
local see_also_section = ""
local parameter_doc = frame:expandTemplate{title = 'پارا', args = {"language", language_code}}
table.insert(layout, get_top_section(frame))
table.insert(layout, string.format(non_english_language_cs1_text_strings["LINE1"], parameter_doc, language_name, language_name))
local see_also_section = get_see_also_section(page_title, language_name, language_code)
local bottom = get_bottom_section(frame, language_name, see_also_section, non_english_language_cs1_text_strings["PARENT_CATEGORY"])
return table.concat(layout, "\n\n") .. bottom
end
--[[ -------------------------- < T E S T _ C A S E S _ S H A R E D _ C O D E > --------------------------
]]
local function compare_by_keys2(a, b) -- local function used by table.sort()
return a[2] < b[2] -- ascending sort by code
end
local function compare_by_keys(a, b) -- local function used by table.sort()
return a[1] < b[1] -- ascending sort by code
end
-- Used by testcases_iso_code_to_name()
local function get_language_code_table_from_code(args)
local entry = {}
--if args.override_table[args.language_code] then
-- table.insert(entry, args.override_table[args.language_code][1]) -- :gsub(' %b()$', '') fails here
--else
table.insert(entry, args.language_code)
-- end
return entry
end
-- Used by testcases_name_from_tag()
local function get_language_code_and_name_table_from_code(args)
local entry = {}
if args.override_table[args.language_code] then
table.insert(entry, args.language_code)
local language_code, _ = args.override_table[args.language_code][1]:gsub(' %b()$', '')
table.insert(entry, language_code)
else
table.insert(entry, args.language_code)
table.insert(entry, args.language_table[args.language_code])
end
return entry
end
-- Used by testcases_category_from_tag()
local function get_language_code_and_category_table_from_code(args)
local entry = {}
table.insert(entry, args.language_code)
table.insert(entry, args.test_function({args.language_code}))
return entry
end
-- Used by testcases_iso_name_to_code() and testcases_tag_from_name()
local function get_language_name_and_code_table_from_code(args)
local entry = {}
if args.override_table[args.language_code] then
table.insert(entry, args.override_table[args.language_code][1]) -- only the first name when there are multiples
table.insert(entry, args.language_code)
else
table.insert(entry, args.language_names[1]) -- only the first name when there are multiples
table.insert(entry, args.language_code)
end
return entry
end
local function get_table(table_function, language_table, length, range, iso_number, test_function)
local table_of_language_name_and_code_tables = {}
local override_table_name = "override"
if iso_number then
override_table_name = "override_" .. iso_number
end
local override_table = require("Module:Language/data/ISO_639_override/sandbox")[override_table_name]
-- For most ISO 639s.
if range then
for language_code, language_names in pairs(language_table) do
if language_code:find(range) then
table.insert(table_of_language_name_and_code_tables, table_function({
override_table = override_table,
language_code = language_code,
language_names = language_names,
test_function = test_function,
language_table = language_table
}))
end
end
-- For ISO 639-1.
elseif length then
for language_code, language_names in pairs(language_table) do
if language_code:len() == 2 then
table.insert(table_of_language_name_and_code_tables, table_function({
override_table = override_table,
language_code = language_code,
language_names = language_names,
test_function = test_function,
language_table = language_table
}))
end
end
-- For general /testcases.
else
for language_code, language_names in pairs(language_table) do
table.insert(table_of_language_name_and_code_tables, table_function({
override_table = override_table,
language_code = language_code,
language_names = language_names,
test_function = test_function,
language_table = language_table
}))
end
end
return table_of_language_name_and_code_tables
end
local function get_undabbed_table(language_list, length, range)
local undabbed_language_table = {} -- for this test, ISO 639-3 language name disambiguators must be removed; un-dabbed names go here
for language_code, language_names in pairs(language_list) do
-- For most ISO 639s.
if range then
if language_code:find(range) then
undabbed_language_table[language_code] = language_names[1]:gsub(' %b()$', '') -- undab and save only the first name; ignore all other names assigned to a code
end
-- For ISO 639-1.
elseif length then
if language_code:len() == 2 then
undabbed_language_table[language_code] = language_names[1]:gsub(' %b()$', '') -- undab and save only the first name; ignore all other names assigned to a code
end
-- For general /testcases.
else
undabbed_language_table[language_code] = language_names[1]:gsub(' %b()$', '')
end
end
return undabbed_language_table
end
--[[ -------------------------- < T E S T C A S E S _ C A T E G O R Y _ F R O M _ T A G > --------------------------
Entry point for the various category_from_tag testcases.
Build a table of test patterns where each entry in the table is a table with two members:
{"<language_code>", "<category name according to Module:Lang>"}
- "Expected" column value is the category name according to Module:Lang.
- "Actual" column value is the result of {{#invoke:Lang/sandbox|category_from_tag|<language_code>}}.
TODO: Currently not working.
]]
local function testcases_category_from_tag(self, args)
local cat_from_tag_function = require('Module:Lang')._category_from_tag
local language_tables = get_table(get_language_code_and_category_table_from_code, args.language_list, args.length, args.range, args.iso_number, cat_from_tag_function)
table.sort(language_tables, compare_by_keys)
self:preprocess_equals_preprocess_many(
'{{#invoke:Lang/sandbox|category_from_tag|', '}}', '', '',
language_tables,
{nowiki=false}
)
end
--[[ -------------------------- < T E S T C A S E S _ N A M E _ F R O M _ T A G > --------------------------
Entry point for the various name_from_tag testcases.
Build a table of test patterns where each entry in the table is a table with two members:
{"<language_code>", "<language_name>"}
- "Expected" column value is the <language_name>.
- "Actual" column value is the result of sandbox version {{#invoke:Lang/sandbox|name_from_tag|<language_code>}}.
]]
local function testcases_name_from_tag(self, args)
local undabbed_language_table = get_undabbed_table(args.language_list, args.length, args.range, nil)
local language_tables = get_table(get_language_code_and_name_table_from_code, undabbed_language_table, args.length, args.range)
table.sort(language_tables, compare_by_keys)
self:preprocess_equals_preprocess_many(
'{{#invoke:Lang/sandbox|name_from_tag|', '}}', '', '',
language_tables,
{nowiki=false}
)
end
--[[ -------------------------- < T E S T C A S E S _ T A G _ F R O M _ N A M E > --------------------------
Entry point for the various tag_from_name testcases.
Build a table of test patterns where each entry in the table is a table with two members:
{"<language_name>", "<language_code>"}
- "Expected" column value is the <language_code>.
- "Actual" column value is the result of sandbox version {{#invoke:Lang/sandbox|tag_from_name|<language_name>}}.
TODO: Currently not working.
]]
local function testcases_tag_from_name(self, args)
local language_tables = get_table(get_language_name_and_code_table_from_code, args.language_list, args.length, args.range, args.iso_number, nil)
table.sort(language_tables, compare_by_keys2)
local ordered_table = {}
table.sort(unordered_table)
for _, key in ipairs(unordered_table) do
table.insert(ordered_table, {key, reverse_table[key]})
end
self:preprocess_equals_preprocess_many(
'{{#invoke:Lang/sandbox|tag_from_name|', '}}', '', '',
language_tables,
{nowiki=false}
)
end
--[[ -------------------------- < T E S T C A S E S _ I S O _ C O D E _ T O _ N A M E > --------------------------
Entry point for the various iso_code_to_name testcases.
Build a table of test patterns where each entry in the table is a table with one member:
{"<language_code>"}
- "Expected" column value is the result of the live version of {{#invoke:ISO 639 name|iso_639_name_to_code|<language_code>}}.
- "Actual" column value is the result of sandbox version {{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|<language_code>}}.
]]
local function testcases_iso_code_to_name(self, args)
local language_tables = get_table(get_language_code_table_from_code, args.language_list, args.length, args.range, args.iso_number, nil)
table.sort(language_tables, compare_by_keys)
self:preprocess_equals_preprocess_many(
'{{#invoke:ISO 639 name/sandbox|iso_639_code_to_name|link=yes|', '}}', '{{#invoke:ISO 639 name|iso_639_code_to_name|link=yes|', '}}',
language_tables,
{nowiki=false}
)
end
--[[ -------------------------- < T E S T C A S E S _ I S O _ N A M E _ T O _ C O D E > --------------------------
Entry point for the various iso_name_to_code testcases.
Build a table of test patterns where each entry in the table is a table with two members:
{"<language_name>", "<language_code>"}
- "Expected" column value is the <language_code>.
- "Actual" column is value the result of {{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|<language_name>}}.
]]
local function testcases_iso_name_to_code(self, args)
local language_tables = get_table(get_language_name_and_code_table_from_code, args.language_list, args.length, args.range, args.iso_number, nil)
table.sort(language_tables, compare_by_keys2)
self:preprocess_equals_preprocess_many(
'{{#invoke:ISO 639 name/sandbox|iso_639_name_to_code|2=' .. args.iso_number .. "|", '}}', '', '',
language_tables,
{nowiki=false}
)
end
--[[ -------------------------- < E X P O R T E D _ F U N C T I O N S > --------------------------
]]
return {
lang_xx_settings = lang_xx_settings,
uses_module = uses_module,
non_english_language_text_category = non_english_language_text_category,
non_english_language_sources_category = non_english_language_sources_category,
non_english_language_cs1_sources_category = non_english_language_cs1_sources_category,
private_tags = private_tags,
-- Module:Lang testcases
testcases_category_from_tag = testcases_category_from_tag,
testcases_name_from_tag = testcases_name_from_tag,
testcases_tag_from_name = testcases_tag_from_name,
-- Module:ISO 639 name testcases
testcases_iso_code_to_name = testcases_iso_code_to_name,
testcases_iso_name_to_code = testcases_iso_name_to_code,
}