Module:Translated

From Pandorabox
Revision as of 21:38, 29 May 2021 by Ywang (talk | contribs) (Created page with "-- This module is created as a proposal to partially replace the existing Template:Translated -- List of languages to check localized pages for local langlist = { de = "...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

-- This module is created as a proposal to partially replace the existing Template:Translated

-- List of languages to check localized pages for
local langlist = {
  de = "🇩🇪",
  ru = "🇷🇺",
  fr = "🇫🇷",
  es = "🇪🇸",
  -- I did not add the flags for zh-hans and zh-hant mainly for political reasons
  ["zh-hans"] = "",
  ["zh-hant"] = "",
}

local function main(frame)
  -- It is common for modules to have wrapper functions. In this case it can be (for example) {{#invoke:Translated|main|{{{pagename|{{NAMESPACE}}:{{BASEPAGENAME}}}}}}}, which should work in most cases.
  local pagename = frame.args.pagename or error("No page name supplied")
  local basestr = string.format([=[
{| class="wikitable"
|-
| '''Other languagues''' || 
[[%s|🇬🇧 English]]
]=], pagename)
  local stringlist = {basestr}
  for lang, icon in pairs(langlist) do
    local title = mw.title.new(pagename .. "/" .. lang)
    if title.exists then -- WARNING: EXPENSIVE OPERATION
      stringlist[#stringlist+1] = string.format(" - [[%s/%s|%s %s]]", pagename, lang, icon, mw.language.fetchLanguageName(lang))
    end
  end
  stringlist[#stringlist+1] = "\n|}"
  return table.concat(stringlist)
end

return {main = main}