ATTENTION! The process of updating WiKi to version Eco 10.x has begun. Those wishing to participate can find out more Information on our ECO Contribution Wiki Discord.

Module:Localization: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 26: Line 26:
end
end


function p.tag(tag)
  l = mw.loadData('Module:Localization/tag_data')
  local translatedTag = l[tag]
  if translatedTag == nil then
    return tag
  end
  return translatedTag
end


function p.translate(frame)
function p.translate(frame)
   local args = Utils.normaliseArgs(frame)
   local args = Utils.normaliseArgs(frame)
   return t(args.msg, args.count)
  local msg = args.msg or args[1]
  local count = tonumber(args.count or args[2])
 
   return p.t(msg, count)
end
end




return p
return p

Latest revision as of 22:45, 7 March 2021

Documentation for this module may be created at Module:Localization/doc

local p = {}
local Utils = require('Module:Utils')


function p.t(msg, count)
  if count == nil then
    count=1
  end

  l = mw.loadData('Module:Localization/data')

  local msgs = l.msgs[msg]

  if msgs == nil then
    mw.log('WARNING: Word not translated: ' .. msg)
    return msg
  end
  
  if count==1 or Utils.tableLen(msgs) == 1 then
    return msgs[1]
  else
    -- Pluralise
    local lang = mw.getContentLanguage()
    return lang:plural(count, msgs)
  end
end

function p.tag(tag)
  l = mw.loadData('Module:Localization/tag_data')
  local translatedTag = l[tag]
  if translatedTag == nil then
    return tag
  end
  return translatedTag
end

function p.translate(frame)
  local args = Utils.normaliseArgs(frame)
  local msg = args.msg or args[1]
  local count = tonumber(args.count or args[2])

  return p.t(msg, count)
end


return p