Zelda Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!

Come join the Zelda Wiki community Discord server!

READ MORE

Zelda Wiki
Advertisement

This module handles interactions with the translations database. It exports querying functions for auto-generating Nomenclature and translation pages.

This module exports the following functions.

fetchTranslations

fetchTranslations(pageName)

Returns

Examples

#InputOutput
The returned data includes translations of synonyms as well. For example, requesting translations of Zora Armor (BotW and TP term) also returns translations of Zora Tunic (OoT term).
1
fetchTranslations("Zora Armor")
{
  {
    translation = "Zora Armor",
    game = "BotW",
    term = "Zora Armor",
    language = "enBr",
  },
  {
    translation = "ゾーラの鎧 (''Zōra no yoroi'')",
    game = "BotW",
    term = "Zora Armor",
    language = "ja",
  },
  {
    translation = "卓拉鎧甲 (''Zhuō lā kǎijiǎ'')",
    game = "BotW",
    term = "Zora Armor",
    language = "zhT",
  },
  {
    translation = "Zora-pantser",
    game = "BotW",
    term = "Zora Armor",
    language = "nl",
  },
  {
    translation = "Armure Zora",
    game = "BotW",
    term = "Zora Armor",
    language = "frC",
  },
  {
    meaning = "Zora armor",
    game = "BotW",
    term = "Zora Armor",
    translation = "Armure zora",
    language = "frF",
  },
  {
    translation = "Zora-Rüstung",
    game = "BotW",
    term = "Zora Armor",
    language = "de",
  },
  {
    translation = "Armatura Zora",
    game = "BotW",
    term = "Zora Armor",
    language = "it",
  },
  {
    translation = "조라의 갑옷 (''Joraui gabot'')",
    game = "BotW",
    term = "Zora Armor",
    language = "ko",
  },
  {
    translation = "Доспехи зора (''Dospekhi zora'')",
    game = "BotW",
    term = "Zora Armor",
    language = "ru",
  },
  {
    translation = "Armadura zora",
    game = "BotW",
    term = "Zora Armor",
    language = "esS",
  },
  {
    translation = "Armadura zora",
    game = "BotW",
    term = "Zora Armor",
    language = "esL",
  },
  {
    meaning = "Zora Clothes",
    game = "OoT",
    language = "ja",
    term = "Zora Armor",
    translation = "ゾーラの服 (''Zōra no Fuku'')",
    reference = "<i>''[[Nintendo Official Guidebook—The Legend of Zelda: Ocarina of Time]]''</i> (Shogakukan)  pg. 149",
  },
}
Requesting Wood (Character) should not return translations of the Wood item in Breath of the Wild.
2
fetchTranslations("Wood (Character)")
{
  {
    translation = "ウッド&nbsp;(''Uddo'')",
    language = "ja",
    game = "ST",
    term = "Wood",
    reference = "''[[The Legend of Zelda: Encyclopedia|Encyclopedia]]'', TOKYOPOP, pg. 286 <sup>(<b><span title=\"Spirit Tracks\" class=\"explain\" style=\"color:yellow\">ST</span></b>)</sup>",
  },
}
Conversely, requesting Wood should only return translations of the item, not the character.
3
fetchTranslations("Wood")
{
  {
    meaning = "Bundle of Firewood",
    game = "BotW",
    term = "Wood",
    translation = "薪の束&nbsp;(''Maki no Taba'')",
    language = "ja",
  },
  {
    translation = "木柴束&nbsp;(''Mùchái shù'')",
    game = "BotW",
    term = "Wood",
    language = "zhT",
  },
  {
    translation = "Brandhout",
    game = "BotW",
    term = "Wood",
    language = "nl",
  },
  {
    meaning = "Wood fagot",
    game = "BotW",
    term = "Wood",
    translation = "Fagot de bois",
    language = "frF",
  },
  {
    translation = "Holzbündel",
    game = "BotW",
    term = "Wood",
    language = "de",
  },
  {
    translation = "Fascio di legna",
    game = "BotW",
    term = "Wood",
    language = "it",
  },
  {
    translation = "장작 묶음&nbsp;(''Jangjak mukkeum'')",
    game = "BotW",
    term = "Wood",
    language = "ko",
  },
  {
    translation = "Дрова&nbsp;(''Drova'')",
    game = "BotW",
    term = "Wood",
    language = "ru",
  },
  {
    translation = "Montón de leña",
    game = "BotW",
    term = "Wood",
    language = "esL",
  },
}

fetchTranslationsByDataPage

fetchTranslationsByDataPage(dataPage, options)

Returns

  • All the translations stored on the given dataPage.

Examples

#InputOutput
4
fetchTranslationsByDataPage("Data:Translations/TLoZ/Characters", { limit = 2 })
{
  {
    jaM = "Fairy",
    de = "Feen",
    term = "Fairy",
    jaR = "<i>[[The Legend of Zelda|''The Legend of Zelda'']]</i> manual, pg. 46",
    game = "TLoZ",
    ru = "N/A",
    nativeterm = "Fairy",
    deR = "<i>''[[The Legend of Zelda: Encyclopedia|Encyclopedia]]''</i> (TOKYOPOP)  pg. 120",
    ja = "妖精&nbsp;(''Yōsei'')",
    deM = "Fairies",
  },
  {
    ja = "ハイリア人&nbsp;(''Hairia-jin'')",
    game = "TLoZ",
    term = "Hylian",
    nativeterm = "Hylian",
    jaR = "<i>''[[The Legend of Zelda: Encyclopedia|Encyclopedia]]''</i> (Tokuma Shoten Publishing)  pg. 10",
  },
}

local p = {}
local h = {}

local Term = require("Module:Term")
local utilsCargo = require("Module:UtilsCargo")
local utilsLanguage = require("Module:UtilsLanguage")
local utilsMarkup = require("Module:UtilsMarkup")
local utilsString = require("Module:UtilsString")
local utilsTable = require("Module:UtilsTable")

local TABLE = "Translations"

local function getLangParams()
	local result = {}
	for i, code in ipairs(utilsLanguage.enum()) do
		table.insert(result, {code, code .. "M", code .. "R"})
	end
	return result
end

local function getFields()
	local fields = utilsTable.concat({"nativeterm", "term", "game"}, unpack(getLangParams()))
    return table.concat(fields, ",")
end

-- Template:Translation/Store
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 frame:callParserFunction({
        name = "#cargo_declare:_table=" .. TABLE,
        args = fields
    })
end

-- Template:Translation/Store/Documentation
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 string.format("<pre>%s</pre>", boilerplate)
end

function p.fetchTranslations(page)
	local whereClause = utilsCargo.allOf({
    	nativeterm = page
	})

	-- Fetch translations of synonyms
	local term = Term.fetchTerm(page)
	if term and not utilsString.endsWith(page, ")") then -- without this ) check, Wood (Character) would also fetch data for BotW Wood
		term = string.gsub(term, "#", "") -- terms with # in them are stored in a version of the page without the #, because MediaWiki. Also Cargo doesn't allow queries with # in them.
		whereClause = whereClause .. " OR " ..utilsCargo.allOf({
	    	term = term
		}, "nativeterm NOT LIKE '%)'") -- without this, requesting "Wood" would also fetch data for Wood (Character)
	end
	local queryResults = utilsCargo.query(TABLE, getFields(), {
		where = whereClause
	})
	return h.formatResults(queryResults, false)
end

-- Returns the rows of the specified page for the specified game
function p.fetchTranslationsByGame(game, subjects)
    local tables = TABLE
    local fields = getFields()
    local queryArgs = {
        where = utilsCargo.allOf(
        	{game = game}, 
        	utilsCargo.IN("nativeterm", subjects)
    	)
    }
    local result = utilsCargo.query(tables, fields, queryArgs)
	
	return h.formatResults(result, true)
end

function p.fetchTranslationsByDataPage(dataPage, options)
	local whereClause = "_pageName LIKE '"..dataPage.."%'"
	local rows = utilsCargo.query("Translations", getFields(), {
		where = whereClause,
		limit = options and options.limit,
	})
	return rows
end

function h.formatResults(rows, groupByTranslationKey)
	local results = {}
	for _, row in ipairs(rows) do
		local subjectTranslations = {}
    	for _, langCode in ipairs(utilsLanguage.enum()) do
    		if utilsString.notEmpty(row[langCode]) then
    	    	table.insert(subjectTranslations, {
    	    		term = row.term,
    	    		game = row.game,
    	    		language = langCode,
    	    		translation = row[langCode], 
    	    		meaning = row[langCode .. "M"], 
    	    		reference = row[langCode .. "R"]
    	    	})
	    	end
		end
		if groupByTranslationKey then
			results[row.nativeterm] = utilsTable.concat(results[row.nativeterm] or {}, subjectTranslations) 
		else
			results = utilsTable.concat(results, subjectTranslations)
		end
	end
	return results
end

p.Documentation = {
	fetchTranslations = {
		params = {"pageName"},
		returns = "[[Template:Nomenclature|Nomenclature]] data for a given article.",
		cases = {
			{
				desc = "The returned data includes translations of synonyms as well. For example, requesting translations of <code>Zora Armor</code> (BotW and TP term) also returns translations of <code>Zora Tunic</code> (OoT term).",
				args = {"Zora Armor"},
			},
			{
				desc = "Requesting <code>Wood (Character)</code> should not return translations of the Wood item in {{BotW|-}}.", -- this used to happen
				args = {"Wood (Character)"},
			},
			{
				desc = "Conversely, requesting <code>Wood</code> should only return translations of the item, not the character.",
				args = {"Wood"},
			},
		},
	},
	fetchTranslationsByDataPage = {
		params = {"dataPage", "options"},
		returns = "All the translations stored on the given <code>dataPage</code>.",
		cases = {
			{
				args = {"Data:Translations/TLoZ/Characters", { limit = 2 } },
			},
		}
	}
}

return p
Advertisement