Remove the length limit on string literals in localised strings
Posted: Sun Jan 05, 2025 2:14 pm
by IsaacOscar
Bassically, for some reason if you try and do prototype.localised_name = {"some.key", str}, the length of 'str' is limited to 200 characters.
For example, you could get this error:
Localised string key is too large: 201 > 200 (limit). in property tree at ROOT.recipe.basic-oil-processing.localised_name[2]
I understand having this limit for localised keys, but programmatically generating text with more than 200 characters seems reasonable. Especially as there is no such limit in the values in the locale file, e.g.
local function locat_fill(depth, pos)
if depth == 0 then
pos.i = pos.i + 200
return pos.str:sub(pos.i - 200, pos.i - 1)
else
local result = {""}
while #result <= 20 and pos.i <= pos.n do
table.insert(result, locat_fill(depth - 1, pos)) end
return result end end
function locat(str)
local pos = {i=1, n = str:len(), str=str}
local depth = 0
local result = locat_fill(depth, pos)
while pos.i <= pos.n do
result = {"", result}
while #result <= 20 and pos.i <= pos.n do
table.insert(result, locat_fill(depth, pos)) end
depth = depth + 1 end
return result end
(Note there is a limit of about 20 to the recursion depth of the {'"}, but using the above locat function it is impossible to reach, as you'd need a string of length 19^20^20 × 200 ≈ 7 octillion. But that's a 93 bit number, so you can't even theoretically have a string that big.)
Re: Remove the length limit on string literals in localised strings
Posted: Sun Jan 05, 2025 2:30 pm
by curiosity
That's weird, since there is no such restriction at runtime.
But I guess you shouldn't be dealing in unlocalized strings right there, that defeats the point of localization.
Re: Remove the length limit on string literals in localised strings
Posted: Sun Jan 05, 2025 2:37 pm
by IsaacOscar
curiosity wrote: Sun Jan 05, 2025 2:30 pm
That's weird, since there is no such restriction at runtime.
Your right, game.print{"", ("x"):rep(300)} works.
curiosity wrote: Sun Jan 05, 2025 2:30 pm
But I guess you shouldn't be dealing in unlocalized strings right there, that defeats the point of localization.
In my case, the strings where actually just [ img=... ] things, so they don't need to be translated.