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" 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
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
base/content/game_mechanics/game_mechanics/company/company.tl:235
base/content/game_mechanics/game_mechanics/company/company_legacy_util.tl:15
… 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
base/content/game_mechanics/game_mechanics/company/company_static_util.tl:31
base/content/game_mechanics/game_mechanics/finance/finances_assets.tl:33
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
… 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
base/content/game_mechanics/game_mechanics/company/company.script.tl:399
base/content/game_mechanics/game_mechanics/company/company_legacy_util.tl:16
base/content/game_mechanics/game_mechanics/emission/emission_legacy_util.tl:15
base/content/game_mechanics/game_mechanics/industries/industries.script.tl:57
base/content/game_mechanics/game_mechanics/towns/town_growth.script.tl:323
… 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
base/content/gui/gui/construction/construction_react_util.tl:156
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
base/content/gui/gui/entity_window/entity_window_util.tl:1051
base/content/gui/gui/entity_window/town_building/town_building.tl:181
… 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/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
base/content/gui/gui/menu/settings_page.tl:1698
base/content/gui/gui/statistics/statistic_depots.tl:250
… 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/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:209
base/content/gui/gui/construction/construction_react_util.tl:2787
base/content/gui/gui/entity_window/line/line_eow.script.tl:207
base/content/gui/gui/entity_window/maintenance_station/maintenance_station_eow.script.tl:200
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:4540
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_window.tl:1806
… 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