This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I have a CSV file for localization pourposes, and I use codes like this "A1001", "A1002", etc...

So I want to concatenate two strings with an integer, so i put the code like this

value = 3
$Label.text = "A1001" + str(value) + "A1002"

In my CVS the A1001 would mean "There are " and A1002 would be " enemies left."
And instead of displaying the localized text like with the other text, it displays this


I would like it to return "There are 3 enemies left."

I would like to know how to concatenate strings with localized text.

PS. Single localized text works perfectly, the issue only arises when concatenating.

I also tried with string formating, adding in the CSV file A1001 = There are %s enemies left. And then in the code:

value = 3
var text_display : String = "A1001"
$Label.text = text_display % value

But it returns "not all arguments converted during string formatting in operator '%'.

Godot version v3.4.2.stable.official [45eaa2daf]
in Engine by (28 points)
edited by

2 Answers

+2 votes
Best answer

After searching on the web, I found this solution that is related with my issue:
Translate text by code

With that I can create the following code:

value = 3
tr(A1001) + str(value) + tr(A1002)

And it works as expected.

But at the end I used text formating instead of concatenation, so i would use one string of text with % and I have to use the tr() command too.

by (28 points)
0 votes

I believed this is what correct concatenation means :)
Characters of string are just letters, adding them means creating longer sentences
What is your exact expected result of this addition "A1001" + value + "A1002" ?

Perhaps You expect just the numbers of string to do the addition ? If so You need to expose them, like :

var strin = "A1001"
var value = 3
var number = strin.lstrip("A") 
$Label.text ="A" + str(int(number)+value)
by (8,188 points)
reshown by

I've updated my question with a correction and clarification for this.
Sorry for not being clear enough, I can see how my question wasn't precise enough.

I see, I don't know anything about localized text, I will be hiding this answer soon, so someone else could see unanswered question

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.