মডিউল:ইংরেজি শনাক্তকরণ

উইকিবই থেকে

এই মডিউলের জন্য মডিউল:ইংরেজি শনাক্তকরণ/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

-- This module implements [[Template:ইংরেজি সনাক্তকরণ]].
-- The output is a copy of the first parameter with any English letters highlighted.
-- The output includes a tracking category if English letters are detected.

local category = '[[বিষয়শ্রেণী:চিত্রের সারাংশ বাংলায় অনুবাদ করা প্রয়োজন]]'
local span = '<span style="color:red"><abbr title="অনুগ্রহ করে এখানকার ইংরেজি লেখা বাংলায় অনুবাদ করুন">'
local close = '</abbr></span>'

local function main(frame)
	local args = frame:getParent().args
	local text = args[1] or ''

	local t= {};																-- table of html-like tags removed from text

	for tag in text:gmatch ('%b<>') do											-- look for an html-like substring
		table.insert (t, tag);													-- save a copy
		text = text:gsub (tag, '~', 1);											-- replace the substring with a 'special character'
	end																			-- tilde used here because it was handy and isnt in the '%a' character set

	local result, count = text:gsub('(%a+)', span .. '%1' .. close)
	if count > 0 then
		if text:find('[[', 1, true) then
			-- Spanning all the text is a reliable way to not break wikilinks.
			result = span .. text .. close
		end
		result = result .. category
	end
	
	for _, tag in ipairs(t) do													-- get each tag from the table of tags
		result = result:gsub ('~', tag, 1);										-- and replace each 'special character' in order
	end

	return result
end

return { main = main }