Module:User:AnomieBOT/LanguageCategoryCreator

-- A module used by AnomieBOT's LanguageCategoryCreator task.
-- See [[Wikipedia:Bots/Requests for approval/AnomieBOT 84]]

local p = {}

-- Map of category patterns to handler types.
local cats = {
    ['Articles containing (.+)-language text'] = 'lang',
    ['Articles with text in (.+) languages'] = 'lang',
    ['Articles with (.+)-language sources %((.+)%)'] = 'in_lang',
    ['Articles with sources in (.+) languages %((.+)%)'] = 'in_lang',
    ['Pages with (.+) IPA'] = 'ipa',
    ['CS1 (.+)-language sources %((.+)%)'] = 'cs1_sources',
    ['CS1 uses (.+)-language script %((.+)%)'] = 'cs1_script',
}

-- List SQL LIKE syntax for supported categories.
function p.list_cat_likes()
    local keys = {}
    for k, v in pairs( cats ) do
    	-- Convert pattern to LIKE syntax.
    	k = k:gsub( '%%', '' ):gsub( ' ', '\\_' ):gsub( '%(%.%+%)', '%%' )
    	table.insert( keys, k )
    end
    return table.concat( keys, '\n' )
end

-- Generate the wikitext for a category page.
function p.generate_cat_wikitext( frame )
	local cat = frame.args.cat
    for k, v in pairs( cats ) do
    	local m = { cat:match( '^' .. k .. '$' ) }
    	if #m > 0 then
    		return p[ v ]( cat, unpack( m ) )
    	end
    end
	return 'ERROR: Unrecognized category'
end

-- Generate the wikitext for a {{lang}} category page
function p.lang( cat, name )
	local mLang = require( 'Module:Lang' )
	local tag = mLang._tag_from_name{ name }
	if tag:find( '^<span' ) then
		return 'ERROR: language name not recognized'
	end
	
	local cat2 = mLang._category_from_tag{ tag }
	if cat2:find( '^<span' ) then
		return 'ERROR: no category for code ' .. tag
	end
	if cat2 ~= 'Category:' .. cat then
		return 'ERROR: category for code ' .. tag .. ' is ' .. cat2 .. ', not Category:' .. cat
	end
	
	return '{{Non-English-language text category}}'
end

-- Generate the wikitext for an {{in lang}} category page
function p.in_lang( cat, name, tag )
	local mLang = require( 'Module:In lang' )
	
	local cat2 = mLang._in_lang{ tag, ['list-cats'] = 'yes' }
	if cat2 == '' then
		return 'ERROR: no category for code ' .. tag
	end
	if cat2 ~= 'Category:' .. cat then
		return 'ERROR: category for code ' .. tag .. ' is ' .. cat2 .. ', not Category:' .. cat
	end

	return '{{Non-English-language sources category}}'
end

-- Generate the wikitext for an {{IPA}} category page
function p.ipa( cat, name )
	local mIpa = require( 'Module:IPA/category documentation' )
	local code = mIpa.lookup_name( name )
	if not code then
		return 'ERROR: language name not recognized'
	end
	
	return '{{IPA language category}}'
end

-- Generate the wikitext for "sources" categories from CS1 templates
function p.cs1_sources( cat, name, tag )
	local mCs1 = require( 'Module:Cs1 documentation support' )
	if mCs1.code_name_pair_exists( { tag, name } ) == nil then
		return 'ERROR: code/name pair does not exist'
	end

	return '{{CS1 language sources}}'
end

-- Generate the wikitext for "script" categories from CS1 templates
function p.cs1_script( cat, name, tag )
	local mCs1 = require( 'Module:Cs1 documentation support' )
	if mCs1.code_name_pair_exists( { tag, name } ) == nil then
		return 'ERROR: code/name pair does not exist'
	end

	return '{{CS1 language script}}'
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.