<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Interpolation doesn’t need escaping, but String(format:) does.<div class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On May 11, 2017, at 02:44, Adam Sutcliffe via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi,<div class=""><br class=""></div><div class="">I've been having an issue with a localised string,, one of which has a percentage sign in it:</div><div class=""><span class="gmail-s1" style="color:rgb(255,91,83);font-family:menlo;font-size:11px"><br class=""></span></div><div class=""><span class="gmail-s1" style="color:rgb(255,91,83);font-family:menlo;font-size:11px">"GAMERANK_5_DESC"</span><span class="gmail-s2" style="font-family:menlo;font-size:11px"> = </span><span class="gmail-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="gmail-s2" style="font-family:menlo;font-size:11px">;</span></div>
<div class=""><div class=""><br class=""></div><div class="">the key is built as such:</div><div class=""><br class=""></div><div class="">Obj-c : <font face="monospace, monospace" class="">NSString *key = <span class="gmail-s1">[</span><span class="gmail-s2">NSString</span><span class="gmail-s1"> </span><span class="gmail-s3">stringWithFormat</span><span class="gmail-s1">:</span><span class="gmail-s4" style="color:rgb(255,91,83)">@"GAMERANK_%@_DESC"</span><span class="gmail-s1">,rank];</span></font></div>
<div class=""><br class=""></div><div class="">Swift: <font face="monospace, monospace" class="">let key = <span class="gmail-s2">"GAMERANK_\(</span>rank)_DESC"</font></div><div class=""><br class=""></div><div class="">Then localised with the same macro: <span class="gmail-s1" style="color:rgb(189,153,255);font-family:menlo;font-size:11px">NSLocalizedString</span><span class="gmail-s2" style="font-family:menlo;font-size:11px">(key, </span><span class="gmail-s3" style="font-family:menlo;font-size:11px">@""</span><span class="gmail-s2" style="font-family:menlo;font-size:11px">);</span></div>
<div class=""><br class=""></div><div class="">The output is different though:</div><div class=""><br class=""></div><div class="">Obj- C = <span style="color:rgb(255,91,83);font-family:menlo;font-size:11px" class="">"Wow! You're racing ahead. Only 5% of our users get here!"</span></div><div class="">Swift = <span style="color:rgb(255,91,83);font-family:menlo;font-size:11px" class="">"Wow! You're racing ahead. Only 5%% of our users get here!"</span></div><div class=""><br class=""></div><div class="">Is this a bug in the swifts localisation parsing? Does the percentage sign not need to be escaped in Swift?</div><div class=""><br class=""></div><div class="">Cheers</div><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><font face="HelveticaNeue-Light" class=""><br class="">–</font></div><div class=""><font face="HelveticaNeue-Medium" class="">ADAM SUTCLIFFE</font></div><div class=""><font face="HelveticaNeue-Light" class="">Software Engineer</font></div><div class=""><font face="Helvetica Neue" class=""><br class=""></font></div><div class=""><font face="HelveticaNeue-Light" class="">–</font></div><div class=""><font face="HelveticaNeue-Light" class=""><a value="+447000000000" style="color:rgb(17,85,204)" class="">+44 (0)7786 692 639</a></font></div><div class=""><font face="HelveticaNeue-Light" class=""><a href="mailto:name@peak.net" style="color:rgb(17,85,204)" target="_blank" class="">adam@peak.net</a></font></div><div class=""><font face="HelveticaNeue-Light" class=""><a href="http://peak.net/" style="color:rgb(17,85,204)" target="_blank" class="">peak.net</a></font></div></div></div>
</div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></body></html>