NSLocalizedString with format

前端 未结 4 655
粉色の甜心
粉色の甜心 2020-12-09 15:01

How would I use NSLocalizedString for this string:

[NSString stringWithFormat:@\"Is “%@“ still correct for “%@“ tap “OK“ otherwise tap “Change“          


        
4条回答
  •  误落风尘
    2020-12-09 15:22

    I just want to add one very helpful definition which I use in many of my projects.

    I've added this function to my header prefix file:

    #define NSLocalizedFormatString(fmt, ...) [NSString stringWithFormat:NSLocalizedString(fmt, nil), __VA_ARGS__]
    

    This allows you to define a localized string like the following:

     "ExampleScreenAuthorizationDescriptionLbl"= "I authorize the payment of %@ to %@.";
    

    and it can be used via:

    self.labelAuthorizationText.text = NSLocalizedFormatString(@"ExampleScreenAuthorizationDescriptionLbl", self.formattedAmount, self.companyQualifier);
    

提交回复
热议问题