• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Elegant Way to Create Localized String
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Elegant Way to Create Localized String


  • Subject: Re: Elegant Way to Create Localized String
  • From: Dave DeLong <email@hidden>
  • Date: Fri, 01 Oct 2010 16:21:36 -0600

Would probably use the numbered replacement format.  In english, your format string would be:

@"%1$@... %2$@... %3$@..."

And in the other language, it'd be:

@"%2$@... %1$@... %3$@..."

Then you'd use it like normal:

NSString * translated = [NSString stringWithFormat:format, value1, value2, value3];

We do this all over the place in an app I work on, and it works very very well.

HTH,

Dave

On Oct 1, 2010, at 4:12 PM, Jason Barker wrote:

> 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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

References: 
 >Elegant Way to Create Localized String (From: Jason Barker <email@hidden>)

  • Prev by Date: Elegant Way to Create Localized String
  • Next by Date: Re: Continuously running daemon process CFConstantStringRefs build up over time
  • Previous by thread: Elegant Way to Create Localized String
  • Next by thread: Re: Elegant Way to Create Localized String
  • Index(es):
    • Date
    • Thread