Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

swift - "String" specifier in Stringdict

I'm struggling to make "stringdict" rules work as i need. Already managed to make Int values work correctly by using "d" in NSStringFormatValueTypeKey.

But in 1 case I need to pass a string. I use "s" specifier in stringdict but for some reason i get a string with "(null)" instead of my value.

I haven't found any example for working with string values (yes, it doesn't have a plural form but I still need to use stringdict because of localization). Don't know what keys to use as "one","zero" do not make any sense for string.

This is how I format the string

let inMinVal: String = "some text value"     
let format = NSLocalizedString("select %s days to exercise", comment: "")
let retVal = String(format: format, inMinVal)

And here comes my stringdict file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>select %s days to exercise</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>There's no better time to start than now. Select %#@v2_min@ when you are gonna exercise. The sessions intensity will adapt based on your choices.</string>
        <key>v2_min</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>s</string>
            <key>one</key>
            <string>%s DAYS</string>
            <key>zero</key>
            <string>%s DAYS</string>
            <key>other</key>
            <string>%s DAYS</string>
        </dict>
    </dict>
  </dict>
</plist>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...