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
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
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
base/content/mission/mission/mission_framework/mission_end_window_util.tl:167
… 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
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
base/content/gui/gui/layers/layer_public_transport.tl:47
base/content/gui/gui/debug_panel/make_entity_debug_panel.tl:452
… 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
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:75
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_table.tl:26
base/content/gui/gui/menu/mod_manager_react_util.tl:103
base/content/gui/gui/menu/paradox_react_util.tl:109
base/content/gui/gui/main/town_hud_react_util.tl:119
… 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
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
base/content/gui/gui/construction/construction_desc_react_util.tl:58
base/content/gui/gui/construction/construction_react_util.tl:156
… 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
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:746
base/content/gui/gui/menu/savegame_react_util.tl:129
base/content/gui/gui/menu/settings_page.tl:1654
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
… 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
Used in the base game: 10 times in 8 files
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:1853
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:4540
base/content/gui/gui/menu/savegame_react_util.tl:184
base/content/gui/gui/menu/paradox_react_util.tl:545
base/content/gui/gui/construction/construction_react_util.tl:2787
base/content/gui/gui/entity_window/maintenance_station/maintenance_station_eow.script.tl:200
… 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