<div dir="ltr"><div class="gmail_default"><font face="georgia, serif">You should try <a href="https://developer.apple.com/reference/swift/string/1414192-localizedstringwithformat#">localizedStringWithFormat(_:_:)</a>. </font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">`static func localizedStringWithFormat(_ format: String, _ arguments: CVarArg...) -> String`<br></font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Zhaoxin</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, May 12, 2017 at 1:42 AM, Saagar Jha via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Interpolation doesn’t need escaping, but String(format:) does.<div><br><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word">Saagar Jha</div>
</div>
<br><div><blockquote type="cite"><div><div class="h5"><div>On May 11, 2017, at 02:44, Adam Sutcliffe via swift-users <<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>> wrote:</div><br class="m_166946796723764795Apple-interchange-newline"></div></div><div><div><div class="h5"><div dir="ltr">Hi,<div><br></div><div>I've been having an issue with a localised string,, one of which has a percentage sign in it:</div><div><span class="m_166946796723764795gmail-s1" style="color:rgb(255,91,83);font-family:menlo;font-size:11px"><br></span></div><div><span class="m_166946796723764795gmail-s1" style="color:rgb(255,91,83);font-family:menlo;font-size:11px">"GAMERANK_5_DESC"</span><span class="m_166946796723764795gmail-s2" style="font-family:menlo;font-size:11px"> = </span><span class="m_166946796723764795gmail-s1" style="color:rgb(255,91,83);font-family:menlo;font-size:11px">"Wow! You're racing ahead. Only 5%% of our users get here!"</span><span class="m_166946796723764795gmail-s2" style="font-family:menlo;font-size:11px">;</span></div>
<div><div><br></div><div>the key is built as such:</div><div><br></div><div>Obj-c : <font face="monospace, monospace">NSString *key = <span class="m_166946796723764795gmail-s1">[</span><span class="m_166946796723764795gmail-s2">NSString</span><span class="m_166946796723764795gmail-s1"> </span><span class="m_166946796723764795gmail-s3">stringWithFormat</span><span class="m_166946796723764795gmail-s1">:</span><span class="m_166946796723764795gmail-s4" style="color:rgb(255,91,83)">@"GAMERANK_%@<wbr>_DESC"</span><span class="m_166946796723764795gmail-s1">,rank];</span></font></div>
<div><br></div><div>Swift: <font face="monospace, monospace">let key = <span class="m_166946796723764795gmail-s2">"GAMERANK_\(</span>rank)_DESC"</font></div><div><br></div><div>Then localised with the same macro: <span class="m_166946796723764795gmail-s1" style="color:rgb(189,153,255);font-family:menlo;font-size:11px">NSLocalizedString</span><span class="m_166946796723764795gmail-s2" style="font-family:menlo;font-size:11px">(key, </span><span class="m_166946796723764795gmail-s3" style="font-family:menlo;font-size:11px">@""</span><span class="m_166946796723764795gmail-s2" style="font-family:menlo;font-size:11px">);</span></div>
<div><br></div><div>The output is different though:</div><div><br></div><div>Obj- C = <span style="color:rgb(255,91,83);font-family:menlo;font-size:11px">"Wow! You're racing ahead. Only 5% of our users get here!"</span></div><div>Swift = <span style="color:rgb(255,91,83);font-family:menlo;font-size:11px">"Wow! You're racing ahead. Only 5%% of our users get here!"</span></div><div><br></div><div>Is this a bug in the swifts localisation parsing? Does the percentage sign not need to be escaped in Swift?</div><div><br></div><div>Cheers</div><div><br></div>-- <br><div class="m_166946796723764795gmail_signature"><div dir="ltr"><div><font face="HelveticaNeue-Light"><br>–</font></div><div><font face="HelveticaNeue-Medium">ADAM SUTCLIFFE</font></div><div><font face="HelveticaNeue-Light">Software Engineer</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="HelveticaNeue-Light">–</font></div><div><font face="HelveticaNeue-Light"><a value="+447000000000" style="color:rgb(17,85,204)">+44 (0)7786 692 639</a></font></div><div><font face="HelveticaNeue-Light"><a href="mailto:name@peak.net" style="color:rgb(17,85,204)" target="_blank">adam@peak.net</a></font></div><div><font face="HelveticaNeue-Light"><a href="http://peak.net/" style="color:rgb(17,85,204)" target="_blank">peak.net</a></font></div></div></div>
</div></div></div></div>
______________________________<wbr>_________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br></div></blockquote></div><br></div></div><br>______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>