Skip to content

Commit df41612

Browse files
committed
use new translation module
and fix a number of encoding bugs along the way
1 parent bdb1367 commit df41612

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+135
-243
lines changed

armoks-blessing.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ end
233233
-- ---------------------------------------------------------------------------
234234
function adjust_all_dwarves(skillname)
235235
for _,v in ipairs(dfhack.units.getCitizens()) do
236-
print("Adjusting "..dfhack.df2console(dfhack.TranslateName(dfhack.units.getVisibleName(v))))
236+
print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(v)))
237237
brainwash_unit(v)
238238
elevate_attributes(v)
239239
rejuvenate.rejuvenate(v, true)

brainwash.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function brainwash_unit(profile)
2727
return
2828
end
2929

30-
unit_name=dfhack.TranslateName(dfhack.units.getVisibleName(unit))
30+
unit_name = dfhack.df2console(dfhack.units.getReadableName(unit))
3131

3232
print("Previous personality values for "..unit_name)
3333
printall(unit.status.current_soul.personality.traits)

caravan.lua

+3-12
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function commands.list()
6262
print(dfhack.df2console(('%d: %s caravan from %s'):format(
6363
id,
6464
df.creature_raw.find(df.historical_entity.find(car.entity).race).name[2], -- adjective
65-
dfhack.TranslateName(df.historical_entity.find(car.entity).name)
65+
dfhack.translation.translateName(df.historical_entity.find(car.entity).name)
6666
)))
6767
print(' ' .. (df.caravan_state.T_trade_state[car.trade_state] or ('Unknown state: ' .. car.trade_state)))
6868
print((' %d day(s) remaining'):format(math.floor(car.time_remaining / 120)))
@@ -126,24 +126,15 @@ local function isDisconnectedPackAnimal(unit)
126126
end
127127
end
128128

129-
local function getPrintableUnitName(unit)
130-
local visible_name = dfhack.units.getVisibleName(unit)
131-
local profession_name = dfhack.units.getProfessionName(unit)
132-
if visible_name.has_name then
133-
return ('%s (%s)'):format(dfhack.TranslateName(visible_name), profession_name)
134-
end
135-
return profession_name -- for unnamed animals
136-
end
137-
138129
local function rejoin_pack_animals()
139130
print('Reconnecting disconnected pack animals...')
140131
local found = false
141132
for _, unit in ipairs(df.global.world.units.active) do
142133
if unit.flags1.merchant and isDisconnectedPackAnimal(unit) then
143134
local dragger = unit.following
144135
print((' %s <-> %s'):format(
145-
dfhack.df2console(getPrintableUnitName(unit)),
146-
dfhack.df2console(getPrintableUnitName(dragger))
136+
dfhack.df2console(dfhack.units.getReadableName(unit)),
137+
dfhack.df2console(dfhack.units.getReadableName(dragger))
147138
))
148139
unit.relationship_ids[ df.unit_relationship_type.Dragger ] = dragger.id
149140
dragger.relationship_ids[ df.unit_relationship_type.Draggee ] = unit.id

deathcause.lua

+9-11
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ function getDeathStringFromCause(cause)
2525
end
2626

2727
function displayDeathUnit(unit)
28-
local str = ("The %s"):format(getRaceNameSingular(unit.race))
29-
if unit.name.has_name then
30-
str = str .. (" %s"):format(dfhack.TranslateName(unit.name))
31-
end
28+
local str = unit.name.has_name and '' or 'The '
29+
str = str .. dfhack.units.getReadableName(unit)
3230

3331
if not dfhack.units.isDead(unit) then
34-
print(str .. " is not dead yet!")
32+
print(dfhack.df2console(str) .. " is not dead yet!")
3533
return
3634
end
3735

@@ -46,13 +44,13 @@ function displayDeathUnit(unit)
4644
if killer then
4745
str = str .. (", killed by the %s"):format(getRaceNameSingular(killer.race))
4846
if killer.name.has_name then
49-
str = str .. (" %s"):format(dfhack.TranslateName(killer.name))
47+
str = str .. (" %s"):format(dfhack.translation.translateName(dfhack.units.getVisibleName(killer)))
5048
end
5149
end
5250
end
5351
end
5452

55-
print(str .. '.')
53+
print(dfhack.df2console(str) .. '.')
5654
end
5755

5856
-- returns the item description if the item still exists; otherwise
@@ -68,7 +66,7 @@ end
6866
function displayDeathEventHistFigUnit(histfig_unit, event)
6967
local str = ("The %s %s %s in year %d"):format(
7068
getRaceNameSingular(histfig_unit.race),
71-
dfhack.TranslateName(histfig_unit.name),
69+
dfhack.translation.translateName(dfhack.units.getVisibleName(histfig_unit)),
7270
getDeathStringFromCause(event.death_cause),
7371
event.year
7472
)
@@ -77,7 +75,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event)
7775
if slayer_histfig then
7876
str = str .. (", killed by the %s %s"):format(
7977
getRaceNameSingular(slayer_histfig.race),
80-
dfhack.TranslateName(slayer_histfig.name)
78+
dfhack.translation.translateName(dfhack.units.getVisiblename(slayer_histfig))
8179
)
8280
end
8381

@@ -89,7 +87,7 @@ function displayDeathEventHistFigUnit(histfig_unit, event)
8987
end
9088
end
9189

92-
print(str .. '.')
90+
print(dfhack.df2console(str) .. '.')
9391
end
9492

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

113111
if not dfhack.units.isDead(histfig_unit) then
114-
print(("%s is not dead yet!"):format(dfhack.TranslateName(histfig_unit.name)))
112+
print(("%s is not dead yet!"):format(dfhack.df2console(dfhack.units.getReadableName(histfig_unit))))
115113
else
116114
local death_event = getDeathEventForHistFig(histfig.id)
117115
displayDeathEventHistFigUnit(histfig_unit, death_event)

devel/kill-hf.lua

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
-- Kills the specified historical figure
22

3-
--[====[
4-
5-
devel/kill-hf
6-
=============
7-
8-
Kills the specified historical figure, even if off-site, or terminates a
9-
pregnancy. Useful for working around :bug:`11549`.
10-
11-
Usage::
12-
13-
devel/kill-hf [-p|--pregnancy] [-n|--dry-run] HISTFIG_ID
14-
15-
Arguments:
16-
17-
``histfig_id``:
18-
the ID of the historical figure to target
19-
20-
``-p``, ``--pregnancy``:
21-
if specified, and if the historical figure is pregnant, terminate the
22-
pregnancy instead of killing the historical figure
23-
24-
``-n``, ``--dry-run``:
25-
if specified, only print the name of the historical figure
26-
27-
]====]
28-
293
local target_hf = -1
304
local target_pregnancy = false
315
local dry_run = false
@@ -44,7 +18,7 @@ end
4418

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

5024
if dry_run then

devel/unit-path.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function UnitPathUI:onRenderBody(dc)
127127

128128
dc:seek(2,3):pen(COLOR_BLUE):string(prof)
129129
if name and name.has_name then
130-
dc:seek(2,4):pen(COLOR_BLUE):string(dfhack.TranslateName(name))
130+
dc:seek(2,4):pen(COLOR_BLUE):string(dfhack.translation.translateName(name))
131131
end
132132

133133
local cursor = guidm.getCursorPos()

diplomacy.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ function get_civ_list()
2525
end
2626
end
2727
table.insert(civ_list, {
28-
cur_civ_id,
29-
rel_str,
30-
matched,
31-
dfhack.TranslateName(cur_civ.name, true)
28+
cur_civ_id,
29+
rel_str,
30+
matched,
31+
dfhack.translation.translateName(cur_civ.name, true)
3232
})
3333
end
3434
end

do-job-now.lua

+3-16
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@ local function print_help()
66
print(dfhack.script_help())
77
end
88

9-
local function getUnitName(unit)
10-
local language_name = dfhack.units.getVisibleName(unit)
11-
if language_name.has_name then
12-
return dfhack.df2console(dfhack.TranslateName( language_name ))
13-
end
14-
15-
-- animals
16-
return dfhack.units.getProfessionName(unit)
17-
end
18-
199
local function doJobNow(job)
2010
local job_str = dfhack.job.getName(job)
2111
if not job.flags.do_now then
@@ -30,7 +20,7 @@ local function doJobNow(job)
3020
end
3121
local unit = dfhack.job.getWorker(job)
3222
if unit then
33-
print("... by " .. getUnitName(unit) )
23+
print("... by " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
3424
end
3525
end
3626

@@ -64,7 +54,6 @@ end
6454

6555
local function doUnitJobNow(unit)
6656
if dfhack.units.isCitizen(unit) then
67-
--print('This will attempt to make a job of ' .. getUnitName(unit) .. ' a top priority')
6857
local t_job = unit.job
6958
if t_job then
7059
local job = t_job.current_job
@@ -73,10 +62,8 @@ local function doUnitJobNow(unit)
7362
return
7463
end
7564
end
76-
print("Couldn't find any job for " .. getUnitName(unit) )
65+
print("Couldn't find any job for " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
7766
else
78-
--print('This will attempt to make a job with ' .. getUnitName(unit) .. ' a top priority')
79-
8067
local needle = unit.id
8168
for _link, job in utils.listpairs(df.global.world.jobs.list) do
8269
if #job.general_refs > 0 then
@@ -92,7 +79,7 @@ local function doUnitJobNow(unit)
9279
end
9380
end
9481

95-
print("Couldn't find any job involving " .. getUnitName(unit) )
82+
print("Couldn't find any job involving " .. dfhack.df2console(dfhack.units.getReadableName(unit)))
9683
end
9784
end
9885

elevate-mental.lua

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
-- Elevate all the mental attributes of a unit
2-
-- by vjek
3-
local help = [====[
4-
5-
elevate-mental
6-
==============
7-
Set all mental attributes of the selected dwarf to the maximum possible, or
8-
any number numbers between 0 and 5000 passed as an argument:
9-
``elevate-mental 100`` for example would make the dwarf very stupid indeed.
10-
11-
]====]
122

133
function ElevateMentalAttributes(value)
144
local unit=dfhack.gui.getSelectedUnit()
@@ -17,7 +7,7 @@ function ElevateMentalAttributes(value)
177
return
188
end
199
--print name of dwarf
20-
print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
10+
print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(unit)))
2111
--walk through available attributes, adjust current to max
2212
if unit.status.current_soul then
2313
for k,v in pairs(unit.status.current_soul.mental_attrs) do
@@ -42,7 +32,7 @@ if opt ~= nil then
4232
ElevateMentalAttributes(opt)
4333
end
4434
if opt <0 or opt >5000 then
45-
print(help)
35+
print(dfhack.script_help())
4636
print('\n\nInvalid number!')
4737
end
4838
end

elevate-physical.lua

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
-- Elevate all the physical attributes of a unit
2-
-- by vjek
3-
--[====[
4-
5-
elevate-physical
6-
================
7-
Set all physical attributes of the selected dwarf to the maximum possible, or
8-
any number numbers between 0 and 5000 passed as an argument. Higher is
9-
usually better, but an ineffective hammerer can be useful too...
10-
11-
]====]
122

133
function ElevatePhysicalAttributes(value)
144
local unit=dfhack.gui.getSelectedUnit()
@@ -17,7 +7,7 @@ function ElevatePhysicalAttributes(value)
177
return
188
end
199
--print name of dwarf
20-
print("Adjusting "..dfhack.TranslateName(dfhack.units.getVisibleName(unit)))
10+
print("Adjusting "..dfhack.df2console(dfhack.units.getReadableName(unit)))
2111
--walk through available attributes, adjust current to max
2212
if unit.body then
2313
for k,v in pairs(unit.body.physical_attrs) do

embark-anyone.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function embarkAnyone()
6868

6969
-- Find the civ's name, or come up with one
7070
if civ.name.has_name then
71-
label = dfhack.TranslateName(civ.name, true) .. "\n"
71+
label = dfhack.translation.translateName(civ.name, true) .. "\n"
7272
else
7373
label = "Unnamed " ..
7474
dfhack.units.getRaceReadableNameById(civ.race) ..

emigration.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434

3535
function desert(u,method,civ)
3636
u.following = nil
37-
local line = dfhack.TranslateName(dfhack.units.getVisibleName(u)) .. " has "
37+
local line = dfhack.units.getReadableName(u) .. " has "
3838
if method == 'merchant' then
3939
line = line.."joined the merchants"
4040
u.flags1.merchant = true

0 commit comments

Comments
 (0)