I have a few strings that appear in formspecs in my mod and I'm having a hard time figuring out if translated strings need to be escaped. From my testing, it appears that if the original text does not contain any characters that need to be escaped, then the translated string won't need it either even if the translation contains those special characters. However, if the original text does contain characters that need to be escaped, that's when core.formspec_escape is required.
Is my understanding correct? While it generally doesn't hurt anything, I'd rather not be escaping strings that don't need to be.
[Solved] Is core.formspec_escape required for translations?
[Solved] Is core.formspec_escape required for translations?
Last edited by isaiah658 on Mon May 04, 2026 02:12, edited 1 time in total.
- rubenwardy
- Moderator
- Posts: 7104
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: London, United Kingdom
- Contact:
Re: Is core.formspec_escape required for translations?
Yes you are correct. However, you should still always pass translated strings through formspec escape
If your concern is convenience, it's common to make a util function for this called FS
If your concern is convenience, it's common to make a util function for this called FS
Code: Select all
local function FS(...)
return core.formspec_escape(S(...))
end
-- use in formspec like S
FS("Some text")
- Linuxdirk
- Member
- Posts: 3416
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: Is core.formspec_escape required for translations?
… which makes it impossible to translate strings using the common gettext tooling.rubenwardy wrote: ↑Sun May 03, 2026 14:35If your concern is convenience, it's common to make a util function for this called FS
Code: Select all
local function FS(...) return core.formspec_escape(S(...)) end -- use in formspec like S FS("Some text")
- rubenwardy
- Moderator
- Posts: 7104
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: London, United Kingdom
- Contact:
Re: Is core.formspec_escape required for translations?
Not true, no less so than using S("Hello")Linuxdirk wrote: ↑Sun May 03, 2026 18:30… which makes it impossible to translate strings using the common gettext tooling.rubenwardy wrote: ↑Sun May 03, 2026 14:35If your concern is convenience, it's common to make a util function for this called FS
Code: Select all
local function FS(...) return core.formspec_escape(S(...)) end -- use in formspec like S FS("Some text")
Our example xgettext script supports FS: https://github.com/luanti-org/modtools/ ... text.sh#L3
- Linuxdirk
- Member
- Posts: 3416
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: Is core.formspec_escape required for translations?
Ah, yes, I was stupid 🤣 We can just add more keywords!
Who is online
Users browsing this forum: No registered users and 2 guests