Skip to content

lang_util

Source: base/tealdef/scripts/lang_util.d.tl

Notes

Types of /scripts/lang_util.tl (LangUtil): formatting of translated texts and numbers for the GUI. It wraps StringUtil.format and the engine's api.util.lang functions. Load it with local lang_util = ug_require "/scripts/lang_util.tl" as LangUtil.

Example

-- from base/content/game_mechanics/game_mechanics/notifications/types/animaldespawn.script.tl
description = lang_util.format(_("{animalName} became a victim of technological advance. It is now on its way to heaven."), { animalName = animalName }),

LangUtil

record global base/tealdef/scripts/lang_util.d.tl:3

global record LangUtil

Load: local lang_util = ug_require "/scripts/lang_util.tl"

Notes

Text formatting helpers for the GUI, returned by ug_require "/scripts/lang_util.tl".

Functions

format(string, {string : string}) : string base/tealdef/scripts/lang_util.d.tl:4

Call as lang_util.format

Notes

Same as StringUtil.format; fills {name} placeholders, typically in a translated _("...") text.

Returns string

Example

return lang_util.format(_("There is no electrified path for {vehicle}."), { vehicle = names[1] })
Used in the base game: 429 times in 113 files

base/content/terrain/reforestation.script.tl:33

log.warning(lang_util.format("Number of tiles per month or steps changed. Old number of tiles was {oldTiles}, new is {newTiles}. Old number of steps was {oldSte
base/content/base/base/difficulty_util.tl:239
log.warning(lang_util.format("Did not find {modParam}, hence no difficulty scale can be provided.", { modParam = modParam }))
base/content/mission/mission/notification.script.tl:34
description = lang_util.format(_("Congratulations! You completed the task '{NAME}' and you received a reward of {REWARD} for completing it."), {
base/content/mission/mission/mission_framework/mission_legacy_util.tl:15
log.message(lang_util.format("Updating legacy mission state from version: {fromVersion} to version: {toVersion}", {
base/content/mission/mission/mission_framework/mission_framework_react_util.tl:41
text = lang_util.format(_("{currentProgress} per Year"), {
base/content/mission/mission/mission_framework/mission_end_window_util.tl:167
return lang_util.format(_("Congratulations, you have successfully completed the mission \"{mission}\"!"), { mission = missionDesc and missionDesc.name or "" })
… and 107 more files.

formatInt(integer) : string base/tealdef/scripts/lang_util.d.tl:5

Call as lang_util.formatInt

Notes

Formats an integer for display, using the engine's api.util.lang.formatInt.

Returns string

Used in the base game: 237 times in 60 files

base/content/landmarks/landmarks_notification.script.tl:49

text = text .. lang_util.formatInt(amount) .. "/" .. lang_util.formatInt(requiredAmount) .. " " .. cargoType.name .. " "
base/content/mission/mission/mission_framework/mission_framework_react_util.tl:42
currentProgress = lang_util.formatInt(progress.counter.current)
base/content/mission/mission/tasks/transport_cargo/transport_cargo_faster.tl:31
log.message(lang_util.format(_("Adversary delivery rate = {rate}/year"), { rate= lang_util.formatInt(rate) }))
base/content/gui/gui/music_player/music_player.tl:74
playlistIndex = lang_util.formatInt(state.playlistIndex),
base/content/gui/gui/layers/layer_public_transport.tl:47
local label = lang_util.formatInt(happiness.totalWaiting)
base/content/gui/gui/debug_panel/make_entity_debug_panel.tl:452
text = text .. lang_util.format(("{name}: Last Year: {count}, In Stock: {current}/{total}\n"), { name = cargoName, count = lang_util.formatInt(amount), current 
… and 54 more files.

formatPlainInt(integer) : string base/tealdef/scripts/lang_util.d.tl:6

Call as lang_util.formatPlainInt

Notes

Converts an integer to a string with tostring, without any locale formatting.

Returns string

Used in the base game: 23 times in 13 files

base/content/mission/mission/mission_framework/mission_legacy_util.tl:16

fromVersion = lang_util.formatPlainInt(version),
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:75
from = lang_util.formatPlainInt(elemStatic.vehicleData.yearFrom),
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_table.tl:26
yearFrom = lang_util.formatPlainInt(elem.static.vehicleData.yearFrom),
base/content/gui/gui/menu/mod_manager_react_util.tl:103
code = lang_util.formatPlainInt(err.code)
base/content/gui/gui/menu/paradox_react_util.tl:109
code = lang_util.formatPlainInt(err as integer)
base/content/gui/gui/main/town_hud_react_util.tl:119
text = "(" .. lang_util.formatPlainInt(reactState:old().population) .. (iconPath ~= nil and "" or ")"),
… and 7 more files.

formatNumber(value : number, decimals : integer) : string base/tealdef/scripts/lang_util.d.tl:7

Call as lang_util.formatNumber

Notes

Formats a number with the given number of decimals, using the engine's api.util.lang.formatNumber.

Parameter Type Description
value number The number.
decimals integer Number of decimal places.

Returns string

Used in the base game: 28 times in 10 files

base/content/gui/gui/layers/layer_react_util.tl:78

current = lang_util.formatNumber(mouseValueState:old()[1], 4),
base/content/gui/gui/debug_panel/make_entity_debug_panel.tl:438
local tooltip = lang_util.format("{label}: {value}", { label = v.name, value = lang_util.formatNumber(v.getRating(entityId, townState), 2) })
base/content/gui/gui/game_bar/game_bar_widgets.tl:365
speedFactorText = lang_util.format(_("{value}x"), { value = lang_util.formatNumber(selectedFactor, 2) })
base/content/gui/gui/menu/savegame_react_util.tl:1634
currentValue = lang_util.formatNumber(currentValue, decimals),
base/content/gui/gui/construction/construction_desc_react_util.tl:58
return lang_util.formatNumber(minMax.min, minMax.min < 1 and 1 or 0)
base/content/gui/gui/construction/construction_react_util.tl:156
return lang_util.formatNumber(value, 1)
… and 4 more files.

stringContains(string, string) : boolean base/tealdef/scripts/lang_util.d.tl:9

Call as lang_util.stringContains

Notes

Text search used by the GUI (api.util.lang.stringContains); true if the first string contains the second.

Returns boolean

Used in the base game: 30 times in 12 files

base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:1666

if searchString == "" or lang_util.stringContains(lineName, searchString) then
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:746
if not lang_util.stringContains(elemStatic.name, filter.text) then
base/content/gui/gui/menu/savegame_react_util.tl:129
if not filter or lang_util.stringContains(savegame.saveName, filter) then
base/content/gui/gui/menu/settings_page.tl:1654
if not lang_util.stringContains(desc.uiName, keyBindingsFilterState:old()) then
base/content/gui/gui/menu/mod_selector_page.tl:1930
return lang_util.stringContains(modInfo.title, modSelectorProvider:get():getDisplayData().searchString)
base/content/gui/gui/statistics/statistic_warehouses.tl:375
if lang_util.stringContains(warehouseName, params.searchString) then
… and 6 more files.

compareStrings(string, string) : integer base/tealdef/scripts/lang_util.d.tl:10

Call as lang_util.compareStrings

Notes

Compares two strings for sorting (api.util.lang.compareStrings); negative if the first sorts before the second.

Returns integer

Example

-- from base/content/game_mechanics/game_mechanics/notifications/gui/notification_log.tl
table.sort(list, function(a, b) return lang_util.compareStrings(a, b) < 0 end)
Used in the base game: 10 times in 8 files

base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:1853

local cmp = lang_util.compareStrings(a.dynamic.sortKey as string, b.dynamic.sortKey as string)
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:4540
return lang_util.compareStrings(a.lineName, b.lineName) < 0
base/content/gui/gui/menu/savegame_react_util.tl:184
return lang_util.compareStrings(groupA, groupB) > 0
base/content/gui/gui/menu/paradox_react_util.tl:545
return lang_util.compareStrings(a.name, b.name) < 0
base/content/gui/gui/construction/construction_react_util.tl:2787
return lang_util.compareStrings(a.name, b.name) < 0
base/content/gui/gui/entity_window/maintenance_station/maintenance_station_eow.script.tl:200
return lang_util.compareStrings(aName, bName) < 0
… and 2 more files.

formatPercentageBoost(value : number) : string base/tealdef/scripts/lang_util.d.tl:12

Call as lang_util.formatPercentageBoost

Notes

Formats a fraction as a signed percentage (+12%, -5%) with api.util.toStringPercent; zero gets no sign.

Parameter Type Description
value number The fraction (for example 0.12 for +12 %).

Returns string

Used in the base game: 7 times in 2 files

base/content/gui/gui/construction/construction_desc_react_util.tl:121

text = lang_util.format(_("Comfort: {percent}"), { percent = lang_util.formatPercentageBoost(range.min) }),
base/content/gui/gui/main/cargo_react_util.tl:54
return lang_util.format(_("Specialized Warehouse: {boost}"), { boost = lang_util.formatPercentageBoost(warehouseBoost) })