Module:Rare letters

د ويکيسيند لخوا
Jump to navigation Jump to search

Documentation for this module may be created at Module:Rare letters/لاسوند

-- Used to fill [[:Category:Terms by their individual characters]] with [[Template:rare letters]]

local m_languages = require('Module:languages')

local p = {}

function p.get_rare_letters(lang)
    if (code == nil) then return nil end
	
     code = mw.text.trim(tostring(code))
	
    -- Get the languages table
    local languages = mw.loadData('Module:Rare letters/data')
    if (languages == nil) then return nil end
    if (languages[lang:getCode()] == nil) then return nil end
    if (languages[lang:getCode()]['rare'] == nil) then return nil end
 
    -- Rare letters categories
    local cat = ""
    local locall = mw.language.new('en')
    local title = mw.title.getCurrentTitle().text
    
    for i = 1, string.len(title) do
		local l = mw.ustring.find(mw.ustring.sub(title, i, i), tostring(languages[code]['rare']))
		
		if l ~= nil then
	    	cat = cat .. "[[Category:" .. lang:getCanonicalName() .. " terms spelled with " .. locall:uc(mw.ustring.sub(title, i, i)) .. "]]"
		end
	end
	
    return cat

end

function p.get_rare_categories(frame)
    local args = frame:getParent().args
    local language_code = args[1]
    local lang = m_languages.getByCode(language_code)
	
    local rare = p.get_rare_letters(lang)
    if (rare == nil) then rare = '' end
    return rare
end

return p