Developer forum

Forum » Rapido » @Translate() convention when translate is interrupted by variables

@Translate() convention when translate is interrupted by variables

Mafalda Correa
Mafalda Correa
Reply

Hi,

I want to create a translate that has a variables in the middle. Something like "You have added" + productName + "to the cart". I looked at the Rapido conventions for Translations and none match this scenario.

What's the best way to do this? Should I do @Translate("You have added") + productName + @Translate("to the cart")? It concerns me that it creates two distinct translates and that in other languages the same order might not make sense (especially if the sentence is longer and there's more than one variable included.

"You only have a quantity of " + stockLocationQuantity + " available for " + productName + " in Bill and Hold Release. Please remove " + billHoldReleaseDifference + " from your cart."

This is the actual string I want to have, this would create four different translates and it would be a mess to translate to a different language.

Is there a way to create placeholders inside translates to use variables in a single translate?

Regards

 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

What about using string.Format compatible placeholders?

@string.Format(@Translate("You have {0} items in your cart"), numberOfItems);

Imar

 
Mafalda Correa
Mafalda Correa
Reply

Thanks, Imar. That's perfect! 

 

You must be logged in to post in the forum