Hey! I'm trying to implement a Hebrew translation to my game along my English one, and because of how lua works with rtl languages (which it really isn't) I have to reverse the text to print it correctly. So I tried using lua's built in string manipulation in string.reverse, but I'm getting this error while running and trying to print with love.graphics.printf on my main file with the love.draw function: "UTF-8 decoding error: Invalid UTF-8".
To clarify, I am using a font that has Hebrew chars, and tried printing it with manually reversing the text and it worked just fine. I'm using Visual Studio Code to write the game.
I know this can be conquered by just reversing manually or using a site to reverse long strings of text, but I would really like to be able to print Hebrew text semi-native-ly.
Thanks a lot
Getting a UTF-8 error while trying to reverse and print Hebrew text
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Getting a UTF-8 error while trying to reverse and print Hebrew text
It's because you're not reversing the text, you're reversing the codes that make up each character in the text. You have to take into account that UTF-8 uses multiple bytes to encode non-ASCII chars.
(untested)
Code: Select all
local utf8 = require('utf8')
local function reverse(str)
local len, result = utf8.len(str), {}
for _, c in utf8.codes(str) do
result[len] = utf8.char(c)
len = len - 1
end
return table.concat(result)
end
Re: Getting a UTF-8 error while trying to reverse and print Hebrew text
Thanks! Implemented this into a class just to test this and it worked. I wanted to do something like this if it didn't work out but wasn't sure how exactly to pull it off.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests