Teach CheckTranslationReference about translations in Lua scripts
Using the glory of regex, we can scrape any Lua script files that a map includes and locate calls to the UserInterface.Translate method. We can then treat them in the same way as C# fields marked with a TranslationReferenceAttribute. This allows the lint check to validate the translation invoked in the .lua script has a matching entry in the translation .ftl files, with all the required arguments (if any). We can also locate any calls to AddPrimaryObjective or AddSecondaryObjective defined by the utils.lua script, which also accept translation keys. The are a couple of restrictions: - When linting the map, we don't check for keys in the ftl file that are unused. This is because the linter doesn't load all the keys when checking maps. - In order to validate translation arguments with the regex, we require the Lua script to pass the table of arguments inline at the callsite. If it does not, we raise a warning so the user can adjust the code.
This commit is contained in:
committed by
Matthias Mailänder
parent
e8d5c005a2
commit
0bfa53b58d
@@ -87,8 +87,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Atreides.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Atreides.Resources
|
||||
end
|
||||
|
||||
@@ -87,8 +87,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Atreides.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Atreides.Resources
|
||||
end
|
||||
|
||||
@@ -110,8 +110,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Atreides.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Atreides.Resources
|
||||
end
|
||||
|
||||
@@ -110,8 +110,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Atreides.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Atreides.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Atreides.Resources
|
||||
end
|
||||
|
||||
@@ -305,8 +305,8 @@ WorldLoaded = function()
|
||||
|
||||
Trigger.AfterDelay(DateTime.Seconds(2), function()
|
||||
TimerTicks = ContrabandTimes[Difficulty]
|
||||
local time = { ["time"] = Utils.FormatTime(TimerTicks) }
|
||||
local contrabandApproaching = UserInterface.Translate("contraband-approaching-starport-north-in", time)
|
||||
local time = Utils.FormatTime(TimerTicks)
|
||||
local contrabandApproaching = UserInterface.Translate("contraband-approaching-starport-north-in", { ["time"] = time })
|
||||
Media.DisplayMessage(contrabandApproaching, Mentat)
|
||||
end)
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Harkonnen.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Harkonnen.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Harkonnen.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Harkonnen.Resources
|
||||
end
|
||||
|
||||
@@ -87,8 +87,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Harkonnen.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Harkonnen.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Harkonnen.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Harkonnen.Resources
|
||||
end
|
||||
|
||||
@@ -87,8 +87,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Ordos.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Ordos.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Ordos.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Ordos.Resources
|
||||
end
|
||||
|
||||
@@ -87,8 +87,8 @@ Tick = function()
|
||||
end
|
||||
|
||||
if Ordos.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Ordos.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Ordos.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Ordos.Resources
|
||||
end
|
||||
|
||||
@@ -132,8 +132,8 @@ Tick = function()
|
||||
|
||||
if Ordos.IsObjectiveCompleted(CaptureStarport) then
|
||||
if Ordos.Resources ~= CachedResources then
|
||||
local parameters = { ["harvested"] = Ordos.Resources, ["goal"] = SpiceToHarvest }
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources", parameters)
|
||||
local harvestedResources = UserInterface.Translate("harvested-resources",
|
||||
{ ["harvested"] = Ordos.Resources, ["goal"] = SpiceToHarvest })
|
||||
UserInterface.SetMissionText(harvestedResources)
|
||||
CachedResources = Ordos.Resources
|
||||
end
|
||||
|
||||
@@ -211,10 +211,10 @@ Tick = function()
|
||||
FirstIxiansArrived = true
|
||||
SendContraband()
|
||||
elseif (TimerTicks % DateTime.Seconds(1)) == 0 then
|
||||
local time = { ["time"] = Utils.FormatTime(TimerTicks) }
|
||||
local reinforcementsText = UserInterface.Translate("initial-reinforcements-arrive-in", time)
|
||||
local time = Utils.FormatTime(TimerTicks)
|
||||
local reinforcementsText = UserInterface.Translate("initial-reinforcements-arrive-in", { ["time"] = time })
|
||||
if FirstIxiansArrived then
|
||||
reinforcementsText = UserInterface.Translate("additional-reinforcements-arrive-in", time)
|
||||
reinforcementsText = UserInterface.Translate("additional-reinforcements-arrive-in", { ["time"] = time })
|
||||
end
|
||||
|
||||
UserInterface.SetMissionText(reinforcementsText, Ordos.Color)
|
||||
@@ -244,8 +244,8 @@ WorldLoaded = function()
|
||||
|
||||
Trigger.AfterDelay(DateTime.Seconds(2), function()
|
||||
TimerTicks = InitialContrabandTimes[Difficulty]
|
||||
local time = { ["time"] = Utils.FormatTime(TimerTicks) }
|
||||
Media.DisplayMessage(UserInterface.Translate("ixian-reinforcements-in", time), Mentat)
|
||||
local time = Utils.FormatTime(TimerTicks)
|
||||
Media.DisplayMessage(UserInterface.Translate("ixian-reinforcements-in", { ["time"] = time }), Mentat)
|
||||
end)
|
||||
|
||||
Hunt(Atreides)
|
||||
|
||||
@@ -90,7 +90,7 @@ ReinforcementsTicks2 = DateTime.Minutes(10)
|
||||
Reinforcements2 =
|
||||
{
|
||||
"mgg", "2tnk", "2tnk", "2tnk", "2tnk", "truk", "truk", "truk",
|
||||
"truk", "truk", "truk", "1tnk", "1tnk", "jeep", "jeep"
|
||||
"truk", "truk", "truk", "1tnk", "1tnk", "jeep", "jeep"
|
||||
}
|
||||
|
||||
SovietUnits1 =
|
||||
@@ -230,8 +230,8 @@ ManageSovietAircraft = function()
|
||||
end
|
||||
|
||||
SetEvacuateMissionText = function()
|
||||
local attributes = { ["evacuated"] = UnitsEvacuated, ["threshold"] = UnitsEvacuatedThreshold[Difficulty] }
|
||||
local unitsEvacuated = UserInterface.Translate("units-evacuated", attributes)
|
||||
local unitsEvacuated = UserInterface.Translate("units-evacuated",
|
||||
{ ["evacuated"] = UnitsEvacuated, ["threshold"] = UnitsEvacuatedThreshold[Difficulty] })
|
||||
UserInterface.SetMissionText(unitsEvacuated, TextColor)
|
||||
end
|
||||
|
||||
|
||||
@@ -178,8 +178,8 @@ VillageSetup = function()
|
||||
end
|
||||
|
||||
SetCivilianEvacuatedText = function()
|
||||
local attributes = { ["evacuated"] = CiviliansEvacuated, ["threshold"] = CiviliansEvacuatedThreshold }
|
||||
local civiliansEvacuated = UserInterface.Translate("civilians-evacuated", attributes)
|
||||
local civiliansEvacuated = UserInterface.Translate("civilians-evacuated",
|
||||
{ ["evacuated"] = CiviliansEvacuated, ["threshold"] = CiviliansEvacuatedThreshold })
|
||||
UserInterface.SetMissionText(civiliansEvacuated, TextColor)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user