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" as LangUtil

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: 432 times in 114 files

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/game_mechanics/game_mechanics/achievements/achievements.script.tl:85
log.message(lang_util.format("Updating legacy achievement state from version: {fromVersion} to version: {toVersion}", {
base/content/game_mechanics/game_mechanics/celebrations/celebration_react_util.tl:30
return lang_util.format(_("Congratulations, you have just started the delivery of products requested by {townName}!"), {
base/content/game_mechanics/game_mechanics/company/company.script.tl:398
log.message(lang_util.format("Initializing basePopulation with {basePopulation}.", {
base/content/game_mechanics/game_mechanics/company/company.tl:235
text = lang_util.format(
base/content/game_mechanics/game_mechanics/company/company_legacy_util.tl:15
log.message(lang_util.format("Updating legacy company state from version: {fromVersion} to version: {toVersion}", {
… and 108 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: 241 times in 60 files

base/content/game_mechanics/game_mechanics/company/company.script.tl:603

errorMessages[lang_util.format(nGetText("{numPermits} Permit Used Up", "All {numPermits} Permits Used Up", maxPermits), {numPermits = lang_util.formatInt(maxPer
base/content/game_mechanics/game_mechanics/company/company.tl:237
{ population = lang_util.formatInt(currentRank.requiredExp) }
base/content/game_mechanics/game_mechanics/company/company_static_util.tl:31
return lang_util.format(_("Rank {rank}"), {rank = lang_util.formatInt(companyLevel)})
base/content/game_mechanics/game_mechanics/finance/finances_assets.tl:33
label = lang_util.formatInt(numberTotal),
base/content/game_mechanics/game_mechanics/finance/finances_cargo_lifetime.tl:70
text = labelInMilliSeconds == 0 and lang_util.formatInt(0) or util.formatDurationWithCurrentCalenderSpeed(labelInMilliSeconds, millisPerDayState:old(), "Month")
base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:175
postfix = lang_util.format(nGetText("{count} Year", "{count} Years", sliderChartState:old().numYears), { count = lang_util.formatInt(sliderChartState:old().numY
… 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: 25 times in 14 files

base/content/game_mechanics/game_mechanics/achievements/achievements.script.tl:86

fromVersion = lang_util.formatPlainInt(stateVersion),
base/content/game_mechanics/game_mechanics/company/company.script.tl:399
basePopulation = lang_util.formatPlainInt(companiesState.basePopulation)
base/content/game_mechanics/game_mechanics/company/company_legacy_util.tl:16
fromVersion = lang_util.formatPlainInt(version),
base/content/game_mechanics/game_mechanics/emission/emission_legacy_util.tl:15
fromVersion = lang_util.formatPlainInt(version),
base/content/game_mechanics/game_mechanics/industries/industries.script.tl:57
fromVersion = lang_util.formatPlainInt(version),
base/content/game_mechanics/game_mechanics/towns/town_growth.script.tl:323
local logName = "experience_raw_" .. lang_util.formatPlainInt(tier) .. "_" .. source
… and 8 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/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)
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/entity_window/double_slip_switch.tl:378
text = lang_util.formatNumber(state.duration, 1) .. " s",
base/content/gui/gui/entity_window/entity_window_util.tl:1051
return lang_util.formatNumber(val, 0)
base/content/gui/gui/entity_window/town_building/town_building.tl:181
barTooltip = lang_util.format(_("Noise at Building Position: {noise}"), {noise = lang_util.formatNumber(state:old(), 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/mod_selector_page.tl:1963
return lang_util.stringContains(modInfo.title, modSelectorProvider:get():getDisplayData().searchString)
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:1698
if not lang_util.stringContains(desc.uiName, keyBindingsFilterState:old()) then
base/content/gui/gui/statistics/statistic_depots.tl:250
if lang_util.stringContains(depotName, 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/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:209

return lang_util.compareStrings(a, b) < 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/line/line_eow.script.tl:207
return lang_util.compareStrings(a[1], b[1]) < 0
base/content/gui/gui/entity_window/maintenance_station/maintenance_station_eow.script.tl:200
return lang_util.compareStrings(aName, bName) < 0
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:4540
return lang_util.compareStrings(a.lineName, b.lineName) < 0
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:1806
local cmp = lang_util.compareStrings(a.dynamic.sortKey as string, b.dynamic.sortKey as string)
… 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) })