[SOLVED] Text localization via Polyglot extension => "special" characters (commas etc.)

Hi there!

I’ve been using this extension for a year now and it’s been super helpful for me to manage all my game configurations, which I modify through Google Spreadsheet (which I then export to CSV).

Super useful, thanks a lot, @Pawel!

Now, I want to use it for its primary function, which is text localization. However, I’ve encountered an issue where some characters don’t export properly to CSV and cause problems when imported into the game. Examples of such characters include commas, line breaks, and perhaps others that slip my mind at the moment.

How should I manage these characters? Is there a trick to handling them before exporting to CSV? Or do you manage them directly in Defold?

I imagine there could be a workaround where I replace these characters in Google Sheet with temporary characters, then replace them again in Defold.

Basically:
Google Sheets
readable string :arrow_right: string with temporary characters (via SUBSITUTE function) :arrow_right: export csv

Defold
Import csv :arrow_right: string with temporary characters :arrow_right: readable string

What do you think? Is there another solution?

2 Likes

Wow,thank you so much for letting me know! It’s glad it’s useful for someone! :blush:

Yeah, I believe that would be a way to go. It’s like escape characters in string parsing (/n // or /"). You can ask on Defold forum in separate thread or below Defold Polyglot thread and maybe some other users wilk come up with some ideas too :wink:

EDIT: I thought it’s a direct message :sweat_smile:

1 Like

Thank you for your answer!

But have you ever encountered this issue yourself with your game? (if you use Polyglot for text localization)

Anyway, I’ll try out this solution and come back here to let you know if it worked or not :nerd_face:

No, for now I use the same csv parser, but for other purposes (quest design, spells, skills, etc) and everything is English without any special characters, so didn’t encounter this particular issue.

The solution worked as intended :nerd_face:

For those who might be interested:

In my case, I use a global table:

M.T_LOCA_CHARACTERS = {}
M.T_LOCA_CHARACTERS[1] = {
		source = "0comma0", -- the temporary character to be replaced (from csv)
		target = "," -- the actual character
	}
M.T_LOCA_CHARACTERS[2] = {
		source = "0linebreak0", -- the temporary character to be replaced (from csv)
		target = "\n" -- the actual character
	}

And then in the script (should make a function since I’ll re-use it in many scripts):

for i=1,#c.T_LOCA_CHARACTERS do
	text = string.gsub(text, c.T_LOCA_CHARACTERS[i].source, c.T_LOCA_CHARACTERS[i].target)
end



Note: I used the “0XXXX0” format to make 100% sure this string could not be part of an actual game text (maybe someday I’ll use the word “comma” in a sentence, who knows).

At first, I used a format like [comma] / [linebreak], but for some reason, it seemed to create a problem with string.gsub…

For example, here is what I was getting by replacing “[comma]” with “,” :

Before replacement:
image

After replacement (WTF):
image

Looks like the “bracket” characters “[ ]” are causing the problem, but… would you know why?
(not crucial since it works in the end, but I’m still curious)

1 Like