NSLocalizedString with variables Swift

后端 未结 5 1488
北海茫月
北海茫月 2020-12-30 00:17

I\'m trying to figure out how to use NSLocalizedString with variables.

For example, if I want to output \"by Peter and Larry\", in my Localizable.strings

5条回答
  •  无人及你
    2020-12-30 00:57

    This is another way and how I do it.

    let myString = String.localizedStringWithFormat(NSLocalizedString("by %@ and %@", comment: "yourComment"), name1, name2)
    

    basically, the main idea of Localized String with format is like this:

    let math = "Math"
    let science = "Science"
    String.localizedStringWithFormat(NSLocalizedString("I love %@ and %@", comment: "loved Subjects"), math, science)
    

提交回复
热议问题