Skip to content

sf2.text

Text is everything the player reads. Register your mod’s text, look it up as a handle to put in a definition, or patch the game’s own text. Get sf2 with local sf2 = require("sf2").

Register one translation owned by your mod and get its text handle.

Signature: sf2.text.register { id, language, value }

Parameters

Parameter Type Required
definition LocalizationDefinition Required

Fields of LocalizationDefinition

Field Type Required Meaning
id string Required —
language string Required —
value string Required —

Returns: A text handle.

When: Entrypoint.

local desolatorName = sf2.text.register {
id = "item.desolator", language = "eng", value = "Desolator",
}
sf2.text.register { id = "item.desolator", language = "pol", value = "Desolator" }

id is a local key without a namespace; call once per language. Registering the same key and language twice fails, even if one copy is in a TOML file. The game falls back to English when a translation is missing.

Get the text handle that item names, perks and achievements ask for.

Signature: sf2.text.get(key)

Parameters

Parameter Type Required
key string Required

Returns: A text handle. A key nothing registered still works: its text is the key itself, and the game log warns about it.

When: Entrypoint, after the key is registered or present in your localization files.

local name = sf2.text.get("item.training_blade")
-- The game's own text, by its key in the game's English text:
local rat_wave = sf2.text.get("core:localization/RatAbil")

key is your local key or a full localization ID. The result is a handle, not the string; use sf2.text.read for that.

A key that neither your mod nor the game registers does not stop your script: the text shows the key as you wrote it (for example item.training_blade), so a missing line is easy to spot in game, and the game log names it.

Every line of the game’s English text is available as core:localization/<key>, including Eclipse’s own additions (see Reskin the game). The part after core:localization/ ignores capitals, so core:localization/ratabil is the same text.

Turn a text handle into the translated string.

Signature: sf2.text.read(key, language?)

Parameters

Parameter Type Required
key string|LocalizationHandle Required
language string Optional

Returns: A string in the requested language, falling back to eng, then to an empty string. A key nothing registered reads as the key itself.

When: After loading. Get the handle with get during loading and keep it.

-- localizations/eng.toml: charge.status = "Charge: %d%%"
local chargeText = sf2.text.get("charge.status") -- while loading
local label = string.format(sf2.text.read(chargeText), 75)
sf2.ui.update(view, "status", { text = label })

Without language it uses the current game language. The string does not update itself, so read again when you refresh UI. {br} comes back as a line break. With string.format, every language must have the same placeholders.

Replace an existing translation in one language, for example to rename a base-game item.

Signature: sf2.text.patch { target, language, value }

Parameters

Parameter Type Required
definition LocalizationPatch Required

Fields of LocalizationPatch

Field Type Required Meaning
target string Required —
language string Required —
value string Required —

Returns: nil.

When: Entrypoint.

sf2.text.patch {
target = "core:localization/weapon_nunchaku",
language = "eng",
value = "Nunchaku",
}

The target must exist. Any line of the game’s text can be a target, as core:localization/<key> (see sf2.text.get). Two mods patching the same target and language conflict; disabling the mod restores the original.

List the language codes the game offers, such as eng and rus.

Signature: sf2.text.languages()

Returns: An array of language codes. English is always in it.

When: Any time. Usually during loading, to register text in every language.

-- An item must name text your mod owns. Copy a game text into it in every language,
-- so the item's name follows the player's language.
local function own(id, key)
local source = sf2.text.get(key)
local handle
for _, language in ipairs(sf2.text.languages()) do
handle = sf2.text.register { id = id, language = language, value = sf2.text.read(source, language) }
end
return handle
end
local cursedName = own("item.cursed_blade", "core:localization/weapon_nunchaku")

The list is the languages the player can pick in Options: English, every language the game ships text for, and languages mods add with sf2.locales.register. A language with no translation for a key reads its English text, so registering a copy for every language is safe.