String concatenation with localization CSV file

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mike2611

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

A10013A1002

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.

Extra:
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 ‘%’.

:bust_in_silhouette: Reply From: Inces

I believed this is what correct concatenation means :slight_smile:
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)

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.

Mike2611 | 2022-01-14 15:02

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

Inces | 2022-01-14 15:25

:bust_in_silhouette: Reply From: Mike2611

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.