Terraria Wiki
Registrieren
Terraria Wiki
K („Biom“-Suffix)
K (+Ausnahme für „Bee Hive (item)“)
 
(22 dazwischenliegende Versionen desselben/derselben Benutzers/Benutzerin werden nicht angezeigt)
Zeile 1: Zeile 1:
  +
---Table with EN → DE translations
local db = mw.loadData( "Module:Tr/db" )
 
local de = db.de
+
local de = mw.loadData( "Module:Tr/db/de" )
  +
---Table with DE → EN translations
local en = db.en
 
  +
local en = mw.loadData( "Module:Tr/db/en" )
   
local currentFrame
 
local args_table
 
 
local trim = mw.text.trim
 
local trim = mw.text.trim
   
  +
---Holds the arguments from the #invoke call.
  +
local args_table
  +
  +
---Part of the input term that is in parentheses at the end
 
local suffix
 
local suffix
local suffixExceptions = { -- exceptions where suffix is part of the db entry and thus must not be cut off
+
---Set of input terms where the suffix is part of the database entry and must not be cut off
  +
local suffixExceptions = {
"Lindwurmschwanz (Gegenstand)",
 
  +
["Bee Hive (item)"] = true,
"Ichor (Statuseffekt)",
 
  +
["Cursed Sapling (pet)"] = true,
"Ichor (debuff)",
 
  +
["Lindwurmschwanz (Gegenstand)"] = true,
"Kobold (NPC)",
 
"Tagesanbruch (Statuseffekt)",
+
["Ichor (Statuseffekt)"] = true,
  +
["Ichor (debuff)"] = true,
  +
["Kobold (NPC)"] = true,
  +
["Spektralrüstung (Gegenstand)"] = true,
  +
["Tagesanbruch (Statuseffekt)"] = true,
  +
["Verfluchter Schössling (Haustier)"] = true
  +
}
  +
---Table with the translations of the suffixes
  +
local suffixTranslations = {
  +
["NPC"] = "NPC",
  +
["item"] = "Gegenstand",
  +
["buff"] = "Statuseffekt",
  +
["bait"] = "Köder",
  +
["biome"] = "Biom",
  +
["pet"] = "Haustier",
  +
  +
["Gegenstand"] = "item",
  +
["Statuseffekt"] = "buff",
  +
["Köder"] = "bait",
  +
["Biom"] = "biome",
  +
["Haustier"] = "pet"
 
}
 
}
   
  +
---Return a trimmed version of the value of the template parameter with the specified `key`.
  +
---Return `nil` if the parameter is empty or unset.
  +
---@param key string|number
  +
---@return string|nil
 
local getArg = function(key)
 
local getArg = function(key)
 
local value = args_table[key]
 
local value = args_table[key]
Zeile 28: Zeile 55:
 
end
 
end
   
  +
---Replace all linebreaks in the `text` with HTML linebreaks and return it.
function processInp(text)
 
  +
---@param text string
local resultStr = text
 
  +
---@return string
-- escape
 
  +
local nl2br = function(text)
if mw.ustring.find(resultStr, "<br/>") then
 
resultStr = mw.ustring.gsub(resultStr, "<br/>", "\n") -- replace all newlines with ( \n )
+
return mw.ustring.gsub(text, "\n", "<br/>")
  +
end
  +
  +
---Replace all HTML linebreaks in the `text` with actual linebreaks and return it.
  +
---@param text string
  +
---@return string
  +
local br2nl = function(text)
  +
return mw.ustring.gsub(text, "<br/>", "\n")
  +
end
  +
  +
---Replace linebreaks and strip and store the suffix, if necessary.
  +
---@param input string
  +
---@return string
  +
local processInput = function(input)
  +
  +
local processedInput = br2nl(input)
  +
  +
-- if the input term is a suffix exception, then we must not process it, so just return
  +
if suffixExceptions[processedInput] then
  +
return processedInput
 
end
 
end
  +
-- suffix (not managing this with a table in order to improve performance)
 
  +
-- handle suffix
local offset
 
if mw.ustring.find(resultStr, "%(NPC%)")
+
if mw.ustring.find(processedInput, "%(NPC%)") then
  +
suffix = "NPC"
or mw.ustring.find(resultStr, "%(item%)")
 
or mw.ustring.find(resultStr, "%(buff%)")
+
elseif mw.ustring.find(processedInput, "%(item%)") then
  +
suffix = "item"
or mw.ustring.find(resultStr, "%(bait%)")
 
or mw.ustring.find(resultStr, "%(biome%)")
+
elseif mw.ustring.find(processedInput, "%(buff%)") then
  +
suffix = "buff"
or mw.ustring.find(resultStr, "%(Gegenstand%)")
 
or mw.ustring.find(resultStr, "%(Statuseffekt%)")
+
elseif mw.ustring.find(processedInput, "%(bait%)") then
  +
suffix = "bait"
or mw.ustring.find(resultStr, "%(Köder%)")
 
or mw.ustring.find(resultStr, "%(Biom%)") then
+
elseif mw.ustring.find(processedInput, "%(biome%)") then
  +
suffix = "biome"
local skip = false -- is it an exception?
 
  +
elseif mw.ustring.find(processedInput, "%(pet%)") then
for i, v in ipairs(suffixExceptions) do
 
  +
suffix = "pet"
if resultStr == v then
 
  +
elseif mw.ustring.find(processedInput, "%(Gegenstand%)") then
skip = true
 
  +
suffix = "Gegenstand"
end
 
  +
elseif mw.ustring.find(processedInput, "%(Statuseffekt%)") then
end
 
  +
suffix = "Statuseffekt"
if skip == false then
 
if mw.ustring.find(resultStr, "%(NPC%)") then
+
elseif mw.ustring.find(processedInput, "%(Köder%)") then
offset = 7
+
suffix = "Köder"
  +
elseif mw.ustring.find(processedInput, "%(Biom%)") then
suffix = "NPC"
 
  +
suffix = "Biom"
elseif mw.ustring.find(resultStr, "%(item%)") then
 
  +
elseif mw.ustring.find(processedInput, "%(Haustier%)") then
offset = 8
 
suffix = "item"
+
suffix = "Haustier"
elseif mw.ustring.find(resultStr, "%(buff%)") then
 
offset = 8
 
suffix = "buff"
 
elseif mw.ustring.find(resultStr, "%(bait%)") then
 
offset = 8
 
suffix = "bait"
 
elseif mw.ustring.find(resultStr, "%(biome%)") then
 
offset = 9
 
suffix = "biome"
 
elseif mw.ustring.find(resultStr, "%(Gegenstand%)") then
 
offset = 14
 
suffix = "Gegenstand"
 
elseif mw.ustring.find(resultStr, "%(Statuseffekt%)") then
 
offset = 16
 
suffix = "Statuseffekt"
 
elseif mw.ustring.find(resultStr, "%(Köder%)") then
 
offset = 9
 
suffix = "Köder"
 
elseif mw.ustring.find(resultStr, "%(Biom%)") then
 
offset = 8
 
suffix = "Biom"
 
end
 
resultStr = mw.ustring.sub(resultStr, 1, -offset)
 
end
 
 
end
 
end
  +
return resultStr
 
  +
-- strip the suffix
  +
if suffix and suffix ~= '' then
  +
local offset = mw.ustring.len(suffix) + 4
  +
processedInput = mw.ustring.sub(processedInput, 1, -offset)
  +
end
  +
  +
return processedInput
 
end
 
end
   
  +
---Replace linebreaks and append the translated suffix, if necessary.
function processOutp(text)
 
  +
---@param output string
local resultStr = text
 
  +
---@return string
resultStr = escapeOutp(resultStr)
 
  +
local processOutput = function(output)
if suffix then
 
  +
if suffix == "item" then
 
  +
local processedOutput = nl2br(output)
suffix = "Gegenstand"
 
  +
elseif suffix == "buff" then
 
suffix = "Statuseffekt"
+
if suffix and suffix ~= '' then
elseif suffix == "bait" then
+
-- translate the suffix and append it to the output
suffix = "Köder"
+
suffix = suffixTranslations[suffix]
  +
processedOutput = processedOutput .. " (" .. suffix .. ")"
elseif suffix == "biome" then
 
suffix = "Biom"
 
elseif suffix == "Gegenstand" then
 
suffix = "item"
 
elseif suffix == "Statuseffekt" then
 
suffix = "buff"
 
elseif suffix == "Köder" then
 
suffix = "bait"
 
elseif suffix == "Biom" then
 
suffix = "biome"
 
end
 
resultStr = resultStr .. " (" .. suffix .. ")"
 
 
end
 
end
  +
return resultStr
 
  +
return processedOutput
 
end
 
end
   
  +
---Perform a database lookup for the `stringToTranslate` and return its translation, if available.
function escapeOutp(text)
 
  +
---@param stringToTranslate string
local resultStr = text
 
  +
---@param targetLang '"de"'|'"en"'
if mw.ustring.find(resultStr, "\n") then
 
  +
---@param forceLang boolean If set to `false`, then the function will also perform a lookup in the other database if the translation to the `targetLang` failed.
resultStr = mw.ustring.gsub(resultStr, "\n", "<br/>") -- replace all ( \n ) with wikitext newlines
 
  +
---@return string|nil
  +
local lookup = function(stringToTranslate, targetLang, forceLang)
  +
local resultStr
  +
  +
if targetLang == "de" then
  +
if de[stringToTranslate] then
  +
resultStr = de[stringToTranslate]
  +
elseif not forceLang then
  +
resultStr = en[stringToTranslate]
  +
end
  +
  +
elseif targetLang == "en" then
  +
if en[stringToTranslate] then
  +
resultStr = en[stringToTranslate]
  +
elseif not forceLang then
  +
resultStr = de[stringToTranslate]
  +
end
 
end
 
end
  +
 
return resultStr
 
return resultStr
 
end
 
end
  +
-----------------------------------------------------------------
 
   
 
-- main return object
 
-- main return object
 
return {
 
return {
  +
go = function(frame, args)
 
  +
args_table = args or frame.args -- cache
go = function(frame, args)
 
-- init cache
 
currentFrame = frame
 
args_table = args or frame.args
 
   
local _arg1 = getArg(1) or "" -- string to translate
+
local _arg1 = getArg(1) or '' -- string to translate
local _arg2 = getArg(2) -- target language
+
local _arg2 = getArg(2) -- target language
  +
if not _arg2 then
 
  +
if not _arg2 then
_arg2 = "de"-- default: en>de translation
 
  +
_arg2 = "de" -- default: translation EN → DE
end
 
  +
end
local _force = getArg("force")
 
  +
if _force == "false" then
 
  +
local _force = getArg("force") -- whether to prohibit looking in the opposite translation direction if failing
_force = false
 
  +
if _force == "false" then
else
 
_force = true
+
_force = false
  +
else
end
 
  +
_force = true
  +
end
  +
  +
local _safe = getArg("safe") -- whether to return an empty string if translation failed (otherwise the input is returned)
  +
if _safe == "false" then
  +
_safe = false
  +
else
  +
_safe = true
  +
end
  +
  +
-- perform translation
  +
local resultStr = lookup(processInput(_arg1), _arg2, _force)
  +
  +
if resultStr then
  +
-- if translation successful:
  +
return processOutput(resultStr)
  +
else
  +
-- if translation unsuccessful:
  +
-- return empty string if $safe, else return input
  +
return _safe and '' or _arg1
  +
end
  +
end,
  +
  +
-- for invocation from other modules
  +
translate = function(str, targetLang, forceLang)
  +
return lookup(processInput(str), targetLang, forceLang)
  +
end,
  +
  +
printAll = function(frame)
  +
local resultStr = {}
  +
local class = frame.args["class"] or ""
  +
local style = frame.args["style"] or ""
  +
table.insert(resultStr, "<table class=\"terraria " .. class .. " \" style=\"" .. style .. "\">")
  +
table.insert(resultStr, "<th>Englisch</th><th>Deutsch</th>")
  +
for k, v in pairs(de) do
  +
resultStr[#resultStr+1] = "<tr><td>" .. (nl2br(k) or "(unknown)") .. "</td><td>" .. (nl2br(v) or "(unknown)") .. "</td></tr>"
  +
end
  +
table.insert(resultStr, "</table>")
  +
return table.concat(resultStr)
  +
end,
  +
  +
printTemplateDb = function(frame, args)
  +
args_table = args or frame.args -- cache
  +
  +
local introtext = {
  +
"&lt;includeonly&gt;{{#dplvar:set|_tr-de:__OK__|ok&lt;!--",
  +
"",
  +
"// Generated on " .. os.date("!%c") .. " (UTC)",
  +
"// Generated by https://terraria.fandom.com/de/wiki/Template:Tr/db-de/gen",
  +
""
  +
}
  +
local outrotext = {
  +
"",
  +
"--&gt;}}&lt;!--",
  +
"",
  +
"--&gt;&lt;/includeonly&gt;&lt;noinclude&gt;{{data template}}&lt;/noinclude&gt;"
  +
}
   
local inputStr = processInp(_arg1)
+
local dbtext = {}
  +
for enTerm, deTerm in pairs(de) do
local resultStr
 
  +
if enTerm ~= '' then
 
  +
-- ignore those strings that have placeholders in them
if _arg2 == "de" then
 
  +
if not (mw.ustring.find(enTerm, "{") and mw.ustring.find(enTerm, "}")) then
if de[inputStr] then
 
  +
if not (mw.ustring.find(deTerm, "{") and mw.ustring.find(deTerm, "}")) then
resultStr = de[inputStr]
 
  +
dbtext[#dbtext+1] = "|_tr-de:" .. enTerm .. "|" .. deTerm
elseif not _force then
 
  +
end
resultStr = en[inputStr]
 
end
 
elseif _arg2 == "en" then
 
if en[inputStr] then
 
resultStr = en[inputStr]
 
elseif not _force then
 
resultStr = de[inputStr]
 
 
end
 
end
 
end
 
end
  +
end
 
if resultStr then
 
resultStr = processOutp(resultStr)
 
else
 
resultStr = "(unknown)"
 
end
 
 
return resultStr
 
end,
 
 
 
  +
if getArg("raw") then
printAll = function(frame)
 
  +
-- don't add any additional text, just return the raw data
local resultStr = {}
 
  +
return table.concat(dbtext)
local class = frame.args["class"] or ""
 
local style = frame.args["style"] or ""
 
table.insert(resultStr, "<table class=\"terraria " .. class .. " \" style=\"" .. style .. "\">")
 
table.insert(resultStr, "<th>Englisch</th><th>Deutsch</th>")
 
for k, v in pairs(de) do
 
resultStr[#resultStr+1] = "<tr><td>" .. (escapeOutp(k) or "(unknown)") .. "</td><td>" .. (escapeOutp(v) or "(unknown)") .. "</td></tr>"
 
end
 
table.insert(resultStr, "</table>")
 
return table.concat(resultStr)
 
 
end
 
end
  +
  +
local resultStr = {}
  +
table.insert(resultStr, table.concat(introtext, '\n'))
  +
table.insert(resultStr, "--&gt;" .. table.concat(dbtext) .. "&lt;!--")
  +
table.insert(resultStr, table.concat(outrotext, '\n'))
  +
  +
return table.concat(resultStr, '\n')
  +
end
  +
 
}
 
}

Aktuelle Version vom 23. April 2021, 00:48 Uhr

Lua logo Dokumentation Die folgende Dokumentation stammt von der Seite Modul:Tr/Dokumentation. (bearbeiten | Versionsgeschichte)
Siehe auch die englische Modulseite: Module:Tr. Sie enthält möglicherweise umfassendere oder aktuellere Informationen.

Dieses Modul verarbeitet alle Übersetzungsanfragen von {{tr/lua}}. Es sucht dafür in den Modul-Übersetzungsdatenbanken Modul:Tr/db/de und Modul:Tr/db/en nach dem entsprechenden Eintrag.

  • Die Funktion go ist die gewöhnliche Übersetzungsfunktion; sie liefert den übersetzten Eintrag zurück.
  • Die Funktion printAll druckt die gesamte Übersetzungsdatenbank in Form einer Tabelle.
  • Die Funktion printTemplateDb druckt den Code für die Vorlagen-Übersetzungsdatenbank Vorlage:Tr/db-de (da dieser aus der Modul-Datenbank generiert wird).

---Table with EN → DE translations
local de = mw.loadData( "Module:Tr/db/de" )
---Table with DE → EN translations
local en = mw.loadData( "Module:Tr/db/en" )

local trim = mw.text.trim

---Holds the arguments from the #invoke call.
local args_table

---Part of the input term that is in parentheses at the end
local suffix
---Set of input terms where the suffix is part of the database entry and must not be cut off
local suffixExceptions = {
	["Bee Hive (item)"] = true,
	["Cursed Sapling (pet)"] = true,
	["Lindwurmschwanz (Gegenstand)"] = true,
	["Ichor (Statuseffekt)"] = true,
	["Ichor (debuff)"] = true,
	["Kobold (NPC)"] = true,
	["Spektralrüstung (Gegenstand)"] = true,
	["Tagesanbruch (Statuseffekt)"] = true,
	["Verfluchter Schössling (Haustier)"] = true
}
---Table with the translations of the suffixes
local suffixTranslations = {
	["NPC"] = "NPC",
	["item"] = "Gegenstand",
	["buff"] = "Statuseffekt",
	["bait"] = "Köder",
	["biome"] = "Biom",
	["pet"] = "Haustier",

	["Gegenstand"] = "item",
	["Statuseffekt"] = "buff",
	["Köder"] = "bait",
	["Biom"] = "biome",
	["Haustier"] = "pet"
}

---Return a trimmed version of the value of the template parameter with the specified `key`.
---Return `nil` if the parameter is empty or unset.
---@param key string|number
---@return string|nil
local getArg = function(key)
	local value = args_table[key]
	if not value then
		return nil
	end
	value = trim(value)
	if value == "" then
		return nil
	end
	return value
end

---Replace all linebreaks in the `text` with HTML linebreaks and return it.
---@param text string
---@return string
local nl2br = function(text)
	return mw.ustring.gsub(text, "\n", "<br/>")
end

---Replace all HTML linebreaks in the `text` with actual linebreaks and return it.
---@param text string
---@return string
local br2nl = function(text)
	return mw.ustring.gsub(text, "<br/>", "\n")
end

---Replace linebreaks and strip and store the suffix, if necessary.
---@param input string
---@return string
local processInput = function(input)

	local processedInput = br2nl(input)

	-- if the input term is a suffix exception, then we must not process it, so just return
	if suffixExceptions[processedInput] then
		return processedInput
	end

	-- handle suffix
	if mw.ustring.find(processedInput, "%(NPC%)") then
		suffix = "NPC"
	elseif mw.ustring.find(processedInput, "%(item%)") then
		suffix = "item"
	elseif mw.ustring.find(processedInput, "%(buff%)") then
		suffix = "buff"
	elseif mw.ustring.find(processedInput, "%(bait%)") then
		suffix = "bait"
	elseif mw.ustring.find(processedInput, "%(biome%)") then
		suffix = "biome"
	elseif mw.ustring.find(processedInput, "%(pet%)") then
		suffix = "pet"
	elseif mw.ustring.find(processedInput, "%(Gegenstand%)") then
		suffix = "Gegenstand"
	elseif mw.ustring.find(processedInput, "%(Statuseffekt%)") then
		suffix = "Statuseffekt"
	elseif mw.ustring.find(processedInput, "%(Köder%)") then
		suffix = "Köder"
	elseif mw.ustring.find(processedInput, "%(Biom%)") then
		suffix = "Biom"
	elseif mw.ustring.find(processedInput, "%(Haustier%)") then
		suffix = "Haustier"
	end

	-- strip the suffix
	if suffix and suffix ~= '' then
		local offset = mw.ustring.len(suffix) + 4
		processedInput = mw.ustring.sub(processedInput, 1, -offset)
	end

	return processedInput
end

---Replace linebreaks and append the translated suffix, if necessary.
---@param output string
---@return string
local processOutput = function(output)

	local processedOutput = nl2br(output)

	if suffix and suffix ~= '' then
		-- translate the suffix and append it to the output
		suffix = suffixTranslations[suffix]
		processedOutput = processedOutput .. " (" .. suffix .. ")"
	end

	return processedOutput
end

---Perform a database lookup for the `stringToTranslate` and return its translation, if available.
---@param stringToTranslate string
---@param targetLang '"de"'|'"en"'
---@param forceLang boolean If set to `false`, then the function will also perform a lookup in the other database if the translation to the `targetLang` failed.
---@return string|nil
local lookup = function(stringToTranslate, targetLang, forceLang)
	local resultStr

	if targetLang == "de" then
		if de[stringToTranslate] then
			resultStr = de[stringToTranslate]
		elseif not forceLang then
			resultStr = en[stringToTranslate]
		end

	elseif targetLang == "en" then
		if en[stringToTranslate] then
			resultStr = en[stringToTranslate]
		elseif not forceLang then
			resultStr = de[stringToTranslate]
		end
	end

	return resultStr
end
-----------------------------------------------------------------

-- main return object
return {
go = function(frame, args)
	args_table = args or frame.args -- cache

	local _arg1 = getArg(1) or '' -- string to translate
	local _arg2 = getArg(2) -- target language

	if not _arg2 then
		_arg2 = "de" -- default: translation EN → DE
	end

	local _force = getArg("force") -- whether to prohibit looking in the opposite translation direction if failing
	if _force == "false" then
		_force = false
	else
		_force = true
	end

	local _safe = getArg("safe") -- whether to return an empty string if translation failed (otherwise the input is returned)
	if _safe == "false" then
		_safe = false
	else
		_safe = true
	end

	-- perform translation
	local resultStr = lookup(processInput(_arg1), _arg2, _force)

	if resultStr then
		-- if translation successful:
		return processOutput(resultStr)
	else
		-- if translation unsuccessful:
		-- return empty string if $safe, else return input
		return _safe and '' or _arg1
	end
end,

-- for invocation from other modules
translate = function(str, targetLang, forceLang)
	return lookup(processInput(str), targetLang, forceLang)
end,

printAll = function(frame)
	local resultStr = {}
	local class = frame.args["class"] or ""
	local style = frame.args["style"] or ""
	table.insert(resultStr, "<table class=\"terraria " .. class .. " \" style=\"" .. style .. "\">")
	table.insert(resultStr, "<th>Englisch</th><th>Deutsch</th>")
	for k, v in pairs(de) do
		resultStr[#resultStr+1] = "<tr><td>" .. (nl2br(k) or "(unknown)") .. "</td><td>" .. (nl2br(v) or "(unknown)") .. "</td></tr>"
	end
	table.insert(resultStr, "</table>")
	return table.concat(resultStr)
end,

printTemplateDb = function(frame, args)
	args_table = args or frame.args -- cache
	
	local introtext = {
		"&lt;includeonly&gt;{{#dplvar:set|_tr-de:__OK__|ok&lt;!--",
		"",
		"// Generated on " .. os.date("!%c") .. " (UTC)",
		"// Generated by https://terraria.fandom.com/de/wiki/Template:Tr/db-de/gen",
		""
	}
	local outrotext = {
		"",
		"--&gt;}}&lt;!--",
		"",
		"--&gt;&lt;/includeonly&gt;&lt;noinclude&gt;{{data template}}&lt;/noinclude&gt;"
	}

	local dbtext = {}
	for enTerm, deTerm in pairs(de) do
		if enTerm ~= '' then
			-- ignore those strings that have placeholders in them
			if not (mw.ustring.find(enTerm, "{") and mw.ustring.find(enTerm, "}")) then
				if not (mw.ustring.find(deTerm, "{") and mw.ustring.find(deTerm, "}")) then
					dbtext[#dbtext+1] = "|_tr-de:" .. enTerm .. "|" .. deTerm
				end
			end
		end
	end
	
	if getArg("raw") then
		-- don't add any additional text, just return the raw data
		return table.concat(dbtext)
	end

	local resultStr = {}
	table.insert(resultStr, table.concat(introtext, '\n'))
	table.insert(resultStr, "--&gt;" .. table.concat(dbtext) .. "&lt;!--")
	table.insert(resultStr, table.concat(outrotext, '\n'))

	return table.concat(resultStr, '\n')
end

}