FANDOM


--[[
Module:Iconflags
A unified module for HPW's icon, flag and fontawesome classes
by Mfaizsyahmi, 2017
 
notes: 
1. The express intent of this module is to try and incorporate 
   emoji regional indicator (flags) and other emoji.
2. Support using useemoji argument, taking value of o (oasis), 
   m (mobile) or a combination of both (om, mo) indicating for 
   which skin emoji should be used.
3. Hide from mobile using "hidden" class. Hide from oasis using 
   a custom class (or inline css).
  ]]
 
local country = require("Dev:Country")
local getArgs = require("Dev:Arguments").getArgs
local p = {}
 
local regTbl = {
    a = "🇦",
    b = "🇧",
    c = "🇨",
    d = "🇩",
    e = "🇪",
    f = "🇫",
    g = "🇬",
    h = "🇭",
    i = "🇮",
    j = "🇯",
    k = "🇰",
    l = "🇱",
    m = "🇲",
    n = "🇳",
    o = "🇴",
    p = "🇵",
    q = "🇶",
    r = "🇷",
    s = "🇸",
    t = "🇹",
    u = "🇺",
    v = "🇻",
    w = "🇼",
    x = "🇽",
    y = "🇾",
    z = "🇿"
}
 
-- returns regional indicator characters of the input string
local function emojiReg(str)
    local tbl = regTbl
    local s = mw.ustring.lower(str)
    local out = ""
    --mw.log(mw.ustring.len(s))
    for i=1, mw.ustring.len(s) do
        local c = mw.ustring.sub(s,i,i)
        out = out .. (tbl[c] or c)
    end
    return out
end
 
function p.flag(frame)
    -- retrieve arguments
    local args = getArgs(frame)
    local str = mw.ustring.lower(args[1]) or 'de'
    local useemoji = args.useemoji
    if str=='uk' then str='gb' end -- uk->gb
 
    -- init strings
    local emojiFlag = ""
    local defaultStr = '<span class="flag flag-' .. str .. '"></span>'
    local oasisStr = ""
    local mobileStr = ""
 
    -- prepare UTF-8 flag emoji string only if required
    if useemoji~=nil then --regional indicator used
        emojiFlag = emojiReg(args[1])
    end
 
    if useemoji=="o" then
        oasisStr = '<span class="hidden">'..emojiFlag..'</span>'
        --mobile not supported
    elseif useemoji=="m" then
        oasisStr = '<span class="hidden flag flag-'..str..'"></span>'
        mobileStr = '<span class="mobile-only">'..emojiFlag..'</span>'
    elseif useemoji=="om" or useemoji=="mo" then
        oasisStr = emojiFlag
    else
        oasisStr = '<span class="hidden flag flag-'..str..'"></span>'
        --mobile not supported
    end
    return oasisStr .. mobileStr
end
 
 
function p.icon(frame)
    local args = getArgs(frame)
    -- do stuff
end
 
function p.fa(frame)
    -- do stuff
end
 
function p.test(frame)
    return "🇩🇪✋"
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.