How to add regular string placeholders to a translated plurals .stringdict in swift ios

后端 未结 1 966
时光说笑
时光说笑 2020-12-21 06:22

I want to translate this string using a plurar stringdict in swift for iOS

  • stays at %1$@
  • stay at %1$@

Using a simple plural without pla

1条回答
  •  -上瘾入骨i
    2020-12-21 07:01

    Positional parameters n$ are one-based, so in

    let label = String.localizedStringWithFormat(format, kidsIds.count, "Name")
    

    "Name" is the second parameter, and you reference it with %2$@:

    NSStringLocalizedFormatKey
    %#@format@
    format
    
        NSStringFormatSpecTypeKey
        NSStringPluralRuleType
        NSStringFormatValueTypeKey
        li
        one
        Sleeps at %2$@
        other
        Sleep at %2$@
    
    

    In your code, %1$@ refers to the first argument kidsIds.count. That is not a string which leads to the crash.

    Alternatively, put it into the NSStringLocalizedFormatKey:

    NSStringLocalizedFormatKey
    %#@format@ at %@
    format
    
        NSStringFormatSpecTypeKey
        NSStringPluralRuleType
        NSStringFormatValueTypeKey
        li
        one
        Sleeps
        other
        Sleep
    
    

    0 讨论(0)
提交回复
热议问题