NSLocalizedString with format

前端 未结 4 657
粉色の甜心
粉色の甜心 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:08

    Given sentences can be constructed with the variable parts in a different order in some languages then I think you should use positional arguments with [NSString stringWithFormat:]:

    NSString *format = NSLocalizedString(@"number_of_items", @"Number of items");
    

    Which would load the following string for English:

    @"Is \"%1$@\" still correct for \"%2$@\" tap \"OK\" otherwise tap \"Change\" to choose new contact details"
    

    And perhaps something else for French (I don't know French so I won't attempt a translation, but it could well have the first and second argument in a different order):

    "French \"%2$@\" french \"%1$@\" french"
    

    And you can safely format the string as normal:

    NSString *translated = [NSString stringWithFormat:format individual.contactInfo, individual.name];
    

提交回复
热议问题