Elegant Way to Create Localized String
Elegant Way to Create Localized String
- Subject: Elegant Way to Create Localized String
- From: Jason Barker <email@hidden>
- Date: Fri, 1 Oct 2010 16:12:06 -0600
Hi everyone,
I'm working on an app with localized strings. I've got one string
which contains placeholder values and depending upon the user's
language settings, it should format the string with the values in a
different order.
For example, in English, the string would be formatted as: "...
<value1> ... <value2> ... <value3> ...."
In a different language, the string would be formatted as: "...
<value2> ... <value1> ... <value3> ...."
The values are all NSString objects. So far, this is what I've come up with:
NSString *value1 = @"ABCDEFG";
NSString *value2 = @"1234567";
NSString *value3 = @"HIJKLMNOP";
NSMutableString *string = NSLocalizedString(@"MyStringIdentifier",
@""); /* Gets localized string with placeholders. */
string = [string stringByReplacingOccurrencesOfString: @"<value1>"
withString: value1];
string = [string stringByReplacingOccurrencesOfString: @"<value2>"
withString: value2];
string = [string stringByReplacingOccurrencesOfString: @"<value3>"
withString: value3];
Is there an elegant way to write this?
Thanks!
Jason
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden