PhantomCaleb (talk | contribs) (Created page with "local p = {} function p.translate() mw.logObject(Strings) end return p") |
PhantomCaleb (talk | contribs) (Add Merchandise as file type) |
||
(16 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
+ | local utilsString = require("Module:UtilsString") |
||
⚫ | |||
+ | local utilsTable = require("Module:UtilsTable") |
||
− | mw.logObject(Strings) |
||
+ | |||
+ | local strings = {} |
||
+ | |||
+ | function p.loadStrings(tbl) |
||
+ | strings = utilsTable.merge({}, strings, tbl) |
||
end |
end |
||
+ | |||
+ | function p.Message(frame) |
||
+ | local count = frame.args[2] |
||
+ | if count == "plural" then |
||
+ | count = 2 |
||
+ | elseif count then |
||
+ | count = tonumber(count) |
||
+ | end |
||
+ | return p.getString(frame.args[1], { |
||
+ | count = count |
||
+ | }) |
||
+ | end |
||
+ | |||
+ | function p.getString(path, vars) |
||
+ | local code = mw.getContentLanguage():getCode() |
||
+ | local localeStrings = strings[code] |
||
+ | local subkeys = utilsString.split(path, "%.") |
||
+ | |||
+ | local result = localeStrings |
||
+ | for _, subkey in ipairs(subkeys) do |
||
+ | result = result[subkey] |
||
+ | end |
||
+ | if type(result) == "table" then |
||
+ | if vars and vars.count and vars.count > 1 then |
||
+ | result = result[2] |
||
+ | else |
||
+ | result = result[1] |
||
+ | end |
||
+ | end |
||
+ | return utilsString.interpolate(result, vars) |
||
+ | end |
||
+ | |||
⚫ | |||
+ | return p.getString(path, {count = 2}) |
||
+ | end |
||
+ | |||
+ | p.loadStrings({ |
||
+ | en = { |
||
+ | files = { |
||
+ | types = { |
||
+ | artwork = {"Artwork", "Artwork"}, |
||
+ | icon = {"Icon", "Icons"}, |
||
+ | logo = {"Logo", "Logos"}, |
||
+ | map = {"Map", "Maps"}, |
||
+ | merchandise = {"Merchandise", "Merchandise"}, |
||
+ | model = {"Model", "Models"}, |
||
+ | print = {"Printed Media", "Printed Media"}, |
||
+ | photograph = {"Photograph", "Photographs"}, |
||
+ | screenshot = {"Screenshot", "Screenshots"}, |
||
+ | sprite = {"Sprite", "Sprites"}, |
||
+ | symbol = {"Symbol", "Symbols"}, |
||
+ | render = {"Render", "Renders"}, |
||
+ | } |
||
+ | } |
||
+ | } |
||
+ | }) |
||
return p |
return p |
Latest revision as of 15:41, 24 April 2022
Documentation for this module may be created at Module:I18n/Documentation
local p = {}
local utilsString = require("Module:UtilsString")
local utilsTable = require("Module:UtilsTable")
local strings = {}
function p.loadStrings(tbl)
strings = utilsTable.merge({}, strings, tbl)
end
function p.Message(frame)
local count = frame.args[2]
if count == "plural" then
count = 2
elseif count then
count = tonumber(count)
end
return p.getString(frame.args[1], {
count = count
})
end
function p.getString(path, vars)
local code = mw.getContentLanguage():getCode()
local localeStrings = strings[code]
local subkeys = utilsString.split(path, "%.")
local result = localeStrings
for _, subkey in ipairs(subkeys) do
result = result[subkey]
end
if type(result) == "table" then
if vars and vars.count and vars.count > 1 then
result = result[2]
else
result = result[1]
end
end
return utilsString.interpolate(result, vars)
end
function p.plural(path)
return p.getString(path, {count = 2})
end
p.loadStrings({
en = {
files = {
types = {
artwork = {"Artwork", "Artwork"},
icon = {"Icon", "Icons"},
logo = {"Logo", "Logos"},
map = {"Map", "Maps"},
merchandise = {"Merchandise", "Merchandise"},
model = {"Model", "Models"},
print = {"Printed Media", "Printed Media"},
photograph = {"Photograph", "Photographs"},
screenshot = {"Screenshot", "Screenshots"},
sprite = {"Sprite", "Sprites"},
symbol = {"Symbol", "Symbols"},
render = {"Render", "Renders"},
}
}
}
})
return p