Skip to content

Commit

Permalink
Merge pull request #1370 from myk002/myk_translatename
Browse files Browse the repository at this point in the history
use new translation module
  • Loading branch information
myk002 authored Jan 12, 2025
2 parents edde6eb + df41612 commit 22fbed1
Show file tree
Hide file tree
Showing 50 changed files with 135 additions and 243 deletions.
2 changes: 1 addition & 1 deletion armoks-blessing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ end
-- ---------------------------------------------------------------------------
function adjust_all_dwarves(skillname)
for _,v in ipairs(dfhack.units.getCitizens()) do
print("Adjusting "..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(v))))
print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(v)))
brainwash_unit(v)
elevate_attributes(v)
rejuvenate.rejuvenate(v, true)
Expand Down
2 changes: 1 addition & 1 deletion brainwash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function brainwash_unit(profile)
return
end

unit_name=dfhack.TranslateName(dfhack.units.getVisibleName(unit))
unit_name = dfhack.df2console(dfhack.units.getReadableName(unit))

print("Previous personality values for "..unit_name)
printall(unit.status.current_soul.personality.traits)
Expand Down
15 changes: 3 additions & 12 deletions caravan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function commands.list()
print(dfhack.df2console(('%d: %s caravan from %s'):format(
id,
df.creature_raw.find(df.historical_entity.find(car.entity).race).name[2], -- adjective
dfhack.TranslateName(df.historical_entity.find(car.entity).name)
dfhack.translation.translateName(df.historical_entity.find(car.entity).name)
)))
print(' ' .. (df.caravan_state.T_trade_state[car.trade_state] or ('Unknown state: ' .. car.trade_state)))
print((' %d day(s) remaining'):format(math.floor(car.time_remaining / 120)))
Expand Down Expand Up @@ -126,24 +126,15 @@ local function isDisconnectedPackAnimal(unit)
end
end

local function getPrintableUnitName(unit)
local visible_name = dfhack.units.getVisibleName(unit)
local profession_name = dfhack.units.getProfessionName(unit)
if visible_name.has_name then
return ('%s (%s)'):format(dfhack.TranslateName(visible_name), profession_name)
end
return profession_name -- for unnamed animals
end

local function rejoin_pack_animals()
print('Reconnecting disconnected pack animals...')
local found = false
for _, unit in ipairs(df.global.world.units.active) do
if unit.flags1.merchant and isDisconnectedPackAnimal(unit) then
local dragger = unit.following
print((' %s <-> %s'):format(
dfhack.df2console(getPrintableUnitName(unit)),
dfhack.df2console(getPrintableUnitName(dragger))
dfhack.df2console(dfhack.units.getReadableName(unit)),
dfhack.df2console(dfhack.units.getReadableName(dragger))
))
unit.relationship_ids[ df.unit_relationship_type.Dragger ] = dragger.id
dragger.relationship_ids[ df.unit_relationship_type.Draggee ] = unit.id
Expand Down
20 changes: 9 additions & 11 deletions deathcause.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ function getDeathStringFromCause(cause)
end

function displayDeathUnit(unit)
local str = ("The %s"):format(getRaceNameSingular(unit.race))
if unit.name.has_name then
str = str .. (" %s"):format(dfhack.TranslateName(unit.name))
end
local str = unit.name.has_name and '' or 'The '
str = str .. dfhack.units.getReadableName(unit)

if not dfhack.units.isDead(unit) then
print(str .. " is not dead yet!")
print(dfhack.df2console(str) .. " is not dead yet!")
return
end

Expand All @@ -46,13 +44,13 @@ function displayDeathUnit(unit)
if killer then
str = str .. (", killed by the %s"):format(getRaceNameSingular(killer.race))
if killer.name.has_name then
str = str .. (" %s"):format(dfhack.TranslateName(killer.name))
str = str .. (" %s"):format(dfhack.translation.translateName(dfhack.units.getVisibleName(killer)))
end
end
end
end

print(str .. '.')
print(dfhack.df2console(str) .. '.')
end

-- returns the item description if the item still exists; otherwise
Expand All @@ -68,7 +66,7 @@ end
function displayDeathEventHistFigUnit(histfig_unit, event)
local str = ("The %s %s %s in year %d"):format(
getRaceNameSingular(histfig_unit.race),
dfhack.TranslateName(histfig_unit.name),
dfhack.translation.translateName(dfhack.units.getVisibleName(histfig_unit)),
getDeathStringFromCause(event.death_cause),
event.year
)
Expand All @@ -77,7 +75,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event)
if slayer_histfig then
str = str .. (", killed by the %s %s"):format(
getRaceNameSingular(slayer_histfig.race),
dfhack.TranslateName(slayer_histfig.name)
dfhack.translation.translateName(dfhack.units.getVisiblename(slayer_histfig))
)
end

Expand All @@ -89,7 +87,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event)
end
end

print(str .. '.')
print(dfhack.df2console(str) .. '.')
end

-- Returns the death event for the given histfig or nil if not found
Expand All @@ -111,7 +109,7 @@ function displayDeathHistFig(histfig)
end

if not dfhack.units.isDead(histfig_unit) then
print(("%s is not dead yet!"):format(dfhack.TranslateName(histfig_unit.name)))
print(("%s is not dead yet!"):format(dfhack.df2console(dfhack.units.getReadableName(histfig_unit))))
else
local death_event = getDeathEventForHistFig(histfig.id)
displayDeathEventHistFigUnit(histfig_unit, death_event)
Expand Down
28 changes: 1 addition & 27 deletions devel/kill-hf.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
-- Kills the specified historical figure

--[====[
devel/kill-hf
=============
Kills the specified historical figure, even if off-site, or terminates a
pregnancy. Useful for working around :bug:`11549`.
Usage::
devel/kill-hf [-p|--pregnancy] [-n|--dry-run] HISTFIG_ID
Arguments:
``histfig_id``:
the ID of the historical figure to target
``-p``, ``--pregnancy``:
if specified, and if the historical figure is pregnant, terminate the
pregnancy instead of killing the historical figure
``-n``, ``--dry-run``:
if specified, only print the name of the historical figure
]====]

local target_hf = -1
local target_pregnancy = false
local dry_run = false
Expand All @@ -44,7 +18,7 @@ end

local hf = df.historical_figure.find(target_hf)
or qerror('histfig not found: ' .. target_hf)
local hf_name = dfhack.df2console(dfhack.TranslateName(hf.name))
local hf_name = dfhack.df2console(dfhack.translation.translateName(hf.name))
local hf_desc = ('%i: %s (%s)'):format(target_hf, hf_name, dfhack.units.getRaceNameById(hf.race))

if dry_run then
Expand Down
2 changes: 1 addition & 1 deletion devel/unit-path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function UnitPathUI:onRenderBody(dc)

dc:seek(2,3):pen(COLOR_BLUE):string(prof)
if name and name.has_name then
dc:seek(2,4):pen(COLOR_BLUE):string(dfhack.TranslateName(name))
dc:seek(2,4):pen(COLOR_BLUE):string(dfhack.translation.translateName(name))
end

local cursor = guidm.getCursorPos()
Expand Down
8 changes: 4 additions & 4 deletions diplomacy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ function get_civ_list()
end
end
table.insert(civ_list, {
cur_civ_id,
rel_str,
matched,
dfhack.TranslateName(cur_civ.name, true)
cur_civ_id,
rel_str,
matched,
dfhack.translation.translateName(cur_civ.name, true)
})
end
end
Expand Down
19 changes: 3 additions & 16 deletions do-job-now.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ local function print_help()
print(dfhack.script_help())
end

local function getUnitName(unit)
local language_name = dfhack.units.getVisibleName(unit)
if language_name.has_name then
return dfhack.df2console(dfhack.TranslateName( language_name ))
end

-- animals
return dfhack.units.getProfessionName(unit)
end

local function doJobNow(job)
local job_str = dfhack.job.getName(job)
if not job.flags.do_now then
Expand All @@ -30,7 +20,7 @@ local function doJobNow(job)
end
local unit = dfhack.job.getWorker(job)
if unit then
print("... by " .. getUnitName(unit) )
print("... by " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
end
end

Expand Down Expand Up @@ -64,7 +54,6 @@ end

local function doUnitJobNow(unit)
if dfhack.units.isCitizen(unit) then
--print('This will attempt to make a job of ' .. getUnitName(unit) .. ' a top priority')
local t_job = unit.job
if t_job then
local job = t_job.current_job
Expand All @@ -73,10 +62,8 @@ local function doUnitJobNow(unit)
return
end
end
print("Couldn't find any job for " .. getUnitName(unit) )
print("Couldn't find any job for " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
else
--print('This will attempt to make a job with ' .. getUnitName(unit) .. ' a top priority')

local needle = unit.id
for _link, job in utils.listpairs(df.global.world.jobs.list) do
if #job.general_refs > 0 then
Expand All @@ -92,7 +79,7 @@ local function doUnitJobNow(unit)
end
end

print("Couldn't find any job involving " .. getUnitName(unit) )
print("Couldn't find any job involving " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
end
end

Expand Down
14 changes: 2 additions & 12 deletions elevate-mental.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
-- Elevate all the mental attributes of a unit
-- by vjek
local help = [====[
elevate-mental
==============
Set all mental attributes of the selected dwarf to the maximum possible, or
any number numbers between 0 and 5000 passed as an argument:
``elevate-mental 100`` for example would make the dwarf very stupid indeed.
]====]

function ElevateMentalAttributes(value)
local unit=dfhack.gui.getSelectedUnit()
Expand All @@ -17,7 +7,7 @@ function ElevateMentalAttributes(value)
return
end
--print name of dwarf
print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(unit)))
--walk through available attributes, adjust current to max
if unit.status.current_soul then
for k,v in pairs(unit.status.current_soul.mental_attrs) do
Expand All @@ -42,7 +32,7 @@ if opt ~= nil then
ElevateMentalAttributes(opt)
end
if opt <0 or opt >5000 then
print(help)
print(dfhack.script_help())
print('\n\nInvalid number!')
end
end
Expand Down
12 changes: 1 addition & 11 deletions elevate-physical.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
-- Elevate all the physical attributes of a unit
-- by vjek
--[====[
elevate-physical
================
Set all physical attributes of the selected dwarf to the maximum possible, or
any number numbers between 0 and 5000 passed as an argument. Higher is
usually better, but an ineffective hammerer can be useful too...
]====]

function ElevatePhysicalAttributes(value)
local unit=dfhack.gui.getSelectedUnit()
Expand All @@ -17,7 +7,7 @@ function ElevatePhysicalAttributes(value)
return
end
--print name of dwarf
print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(unit)))
--walk through available attributes, adjust current to max
if unit.body then
for k,v in pairs(unit.body.physical_attrs) do
Expand Down
2 changes: 1 addition & 1 deletion embark-anyone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function embarkAnyone()

-- Find the civ's name, or come up with one
if civ.name.has_name then
label = dfhack.TranslateName(civ.name, true) .. "\n"
label = dfhack.translation.translateName(civ.name, true) .. "\n"
else
label = "Unnamed " ..
dfhack.units.getRaceReadableNameById(civ.race) ..
Expand Down
2 changes: 1 addition & 1 deletion emigration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end

function desert(u,method,civ)
u.following = nil
local line = dfhack.TranslateName(dfhack.units.getVisibleName(u)) .. " has "
local line = dfhack.units.getReadableName(u) .. " has "
if method == 'merchant' then
line = line.."joined the merchants"
u.flags1.merchant = true
Expand Down
Loading

0 comments on commit 22fbed1

Please sign in to comment.