0

Does anyone know how to go about localizing dynamic variables in code using xamarin.ios? I have this done for static variables. The example below explains more:

//this work
var test = NSBundle.MainBundle.LocalizedString(“Qty 1234”,”test text”);

//what i need is to figure out how to localize the below
var test = "Qty" + aValue; //where aValue is dynamically generated number ex:1,2,3,4,5

Moreover, how would i go about adjusting the monotouch.dialog element to now display right-to-left i.e caption on the left and value on the right (for arabic text)? Thanks in advance.

John D
  • 639
  • 1
  • 10
  • 20

1 Answers1

0

Use String.Format instead of concatenation:

var test = String.Format(NSBundle.MainBundle.LocalizedString(“Qty {0}”,”test text”), aValue);

This should look for the message "Qty {0}" in your Localized.strings, return the translated format for it, and then the {0} will be replaced by aValue.

Monotouch.Dialog is built on top of UITableView, so the answers to this question ( UITableView support for right to left languages) should apply: You have to write your own UITableViewCells

Community
  • 1
  • 1
Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
  • Thanks for your input. Your provided solution to the first part sugests it will work with values that are saved in Localized.strings eg Qty 1234. What I actually meant by dynamic variables was that I can use Localized.strings to localize the string "Qty" but how would i then structure the staement to understand that 1234 is a number and should now localize it (I dont know prior to running the code what the value of the place holder 1234 actually is. – John D Jul 22 '13 at 20:13
  • Thanks for your input. The first part of your answer will work with values that are saved in Localized.strings eg Qty 1234. What I actually meant is I'd like to use Localized.strings to localize the string "Qty" and then get "1234" localized dynamically (I dont know prior to running the code what the value of the place holder 1234 actually is). As for the second part, i'm already subclassing UITableViewCell but need to figure out how to translate/scale/rotate the view correctly.Thanks – John D Jul 22 '13 at 20:23
  • willing to accept this as fully answered for the second part and partially answered for the first – John D Jul 25 '13 at 08:43