MannedTooth (talk | contribs) No edit summary |
MannedTooth (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
local languages = utilsLanguage.GetCodeSortOrder() |
local languages = utilsLanguage.GetCodeSortOrder() |
||
local tables = 'Translations' |
local tables = 'Translations' |
||
+ | local fields = 'term, game' |
||
− | local fields = 'term, game, enBr, enBrM, ja, jaM, zhS, zhSM, zhT, zhTM, cs, csM, da, daM, nl, nlM, fi, fiM, frC, frCM, frF, frFM, de, deM, he, heM, hu, huM, it, itM, ko, koM, no, noM, pl, plM, ptB, ptBM, ptP, ptPM, ru, ruM, esS, esSM, esL, esLM, sv, svM' |
||
+ | for key, value in ipairs(languages) do |
||
+ | fields = fields .. ", " .. value |
||
+ | end |
||
local queryArgs = { |
local queryArgs = { |
||
where = 'term = "' .. term.fetchTerm("Series", page) .. '"' |
where = 'term = "' .. term.fetchTerm("Series", page) .. '"' |
||
Line 20: | Line 23: | ||
-- Returns the rows of the specified page for the specified game |
-- Returns the rows of the specified page for the specified game |
||
function p.fetchTranslationsByGame(game, page) |
function p.fetchTranslationsByGame(game, page) |
||
+ | local languages = utilsLanguage.GetCodeSortOrder() |
||
local tables = 'Translations' |
local tables = 'Translations' |
||
− | local fields = ' |
+ | local fields = 'term, game' |
+ | for key, value in ipairs(languages) do |
||
+ | fields = fields .. ", " .. value |
||
+ | end |
||
local queryArgs = { |
local queryArgs = { |
||
where = 'term = "' .. term.fetchTerm("Series", page) .. '" AND game = "' .. game .. '"' |
where = 'term = "' .. term.fetchTerm("Series", page) .. '" AND game = "' .. game .. '"' |
||
Line 27: | Line 34: | ||
local result = cargo.query( tables, fields, queryArgs ) |
local result = cargo.query( tables, fields, queryArgs ) |
||
− | return result |
+ | return p.formatResults(result) |
end |
end |
||
Revision as of 00:02, 12 September 2019
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 cargo = mw.ext.cargo
local term = require("Module:Term")
local utilsCode = require("Module:UtilsCode")
local utilsLanguage = require("Module:UtilsLanguage")
-- Returns the rows of the specified page.
function p.fetchTranslations(page)
local languages = utilsLanguage.GetCodeSortOrder()
local tables = 'Translations'
local fields = 'term, game'
for key, value in ipairs(languages) do
fields = fields .. ", " .. value
end
local queryArgs = {
where = 'term = "' .. term.fetchTerm("Series", page) .. '"'
}
local result = cargo.query( tables, fields, queryArgs )
return p.formatResults(result)
end
-- Returns the rows of the specified page for the specified game
function p.fetchTranslationsByGame(game, page)
local languages = utilsLanguage.GetCodeSortOrder()
local tables = 'Translations'
local fields = 'term, game'
for key, value in ipairs(languages) do
fields = fields .. ", " .. value
end
local queryArgs = {
where = 'term = "' .. term.fetchTerm("Series", page) .. '" AND game = "' .. game .. '"'
}
local result = cargo.query( tables, fields, queryArgs )
return p.formatResults(result)
end
function p.formatResults(data)
local languages = utilsLanguage.GetCodeSortOrder()
local formattedResults = {}
for key, value in ipairs(data) do
for key2, value2 in ipairs(languages) do
if not utilsCode.IsEmpty(value[value2]) then
table.insert(formattedResults, {term = value["term"], language = value2, translation = value[value2], meaning = value[value2 .. "M"]})
end
end
end
return formattedResults
end
return p