[Solved] Is core.formspec_escape required for translations?

Post Reply
isaiah658
Member
Posts: 207
Joined: Sun Jan 24, 2016 14:58
Contact:

[Solved] Is core.formspec_escape required for translations?

by isaiah658 » Post

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.
Last edited by isaiah658 on Mon May 04, 2026 02:12, edited 1 time in total.

User avatar
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?

by rubenwardy » Post

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

Code: Select all

local function FS(...)
    return core.formspec_escape(S(...))
end

-- use in formspec like S
FS("Some text")

User avatar
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?

by Linuxdirk » Post

rubenwardy wrote:
Sun May 03, 2026 14:35
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")
… which makes it impossible to translate strings using the common gettext tooling.

User avatar
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?

by rubenwardy » Post

Linuxdirk wrote:
Sun May 03, 2026 18:30
rubenwardy wrote:
Sun May 03, 2026 14:35
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")
… which makes it impossible to translate strings using the common gettext tooling.
Not true, no less so than using S("Hello")

Our example xgettext script supports FS: https://github.com/luanti-org/modtools/ ... text.sh#L3
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
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?

by Linuxdirk » Post

Ah, yes, I was stupid 🤣 We can just add more keywords!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests