This module handles interactions with the translations database. It exports querying functions for auto-generating Nomenclature and translation pages.
Lua error in package.lua at line 80: module 'Module:UtilsCode' not found.
local p = {}
local h = {}
local term = require("Module:Term")
local utilsArg = require("Module:UtilsArg")
local utilsCargo = require("Module:UtilsCargo")
local utilsCode = require("Module:UtilsCode")
local utilsLanguage = require("Module:UtilsLanguage")
local utilsMarkup = require("Module:UtilsMarkup")
local utilsTable = require("Module:UtilsTable")
local TABLE = "Translations"
local function getLangParams()
local result = {}
for i, code in ipairs(utilsLanguage.getCodes()) do
table.insert(result, {code, code .. "M", code .. "R"})
end
return result
end
local function getFields()
local fields = utilsTable.concat({"term", "game"}, unpack(getLangParams()))
return table.concat(fields, ",")
end
function p.Declare(frame)
local fields = {
nativeterm = "String",
term = "Wikitext",
game = "Wikitext",
}
for i, params in ipairs(getLangParams()) do
fields[params[1]] = "Wikitext (size=256;)"
fields[params[2]] = "Wikitext"
fields[params[3]] = "Wikitext"
end
return utilsCargo.declare(TABLE, fields)
end
local validate = utilsArg.validator({
_keys = {
enum = utilsTable.concat({"nativeterm", "term", "game"}, unpack(getLangParams()))
},
nativeterm = {
nonEmpty = true,
}
})
function p.Store(frame)
local args = frame:getParent().args
args = utilsTable.merge({}, args, {
game = mw.text.trim(args[1]),
nativeterm = mw.text.trim(args[2]),
})
args[1] = nil
args[2] = nil
args.term = term.fetchTerm({ game = args.game, term = args.nativeterm })
if not args.term then
return "[[Category:Pages with Invalid or Missing Terms]]"
end
local errCategories = validate(args)
if errCategories then
return utilsMarkup.categories(errCategories)
end
return utilsCargo.store(TABLE, args)
end
function p.Boilerplate(frame)
local lines = {"{{Translation/Store||"}
for i, params in ipairs(getLangParams()) do
for j, param in ipairs(params) do
params[j] = "|" .. param .. "= "
end
table.insert(lines, table.concat(params))
end
table.insert(lines, "}}")
local boilerplate = table.concat(lines, "\n")
return utilsMarkup.pre(boilerplate)
end
-- Returns the rows of the specified page.
function p.fetchTranslations(page)
local tables = TABLE
local fields = getFields()
local queryArgs = {
where = 'term = "' .. term.fetchTerm({game = "Series", term = page}) .. '"',
limit = 5000
}
local result = utilsCargo.query( tables, fields, queryArgs )
return h.formatResults(result)
end
-- Returns the rows of the specified page for the specified game
function p.fetchTranslationsByGame(game)
local tables = TABLE
local fields = getFields()
local queryArgs = {
where = 'game = "' .. game .. '"',
limit = 5000
}
local result = utilsCargo.query( tables, fields, queryArgs )
return h.formatResults(result)
end
function h.formatResults(data)
local formattedResults = {}
for key, value in ipairs(data) do
for key2, value2 in ipairs(utilsLanguage.getCodes()) do
if not utilsCode.IsEmpty(value[value2]) then
table.insert(formattedResults, {term = value["term"], game = value["game"], language = value2, translation = value[value2], meaning = value[value2 .. "M"], reference = value[value2 .. "R"]})
end
end
end
return formattedResults
end
return p