<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I have already give a workable implementation above.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="georgia, serif" style="font-size:12.800000190734863px">let count = 10<br></font><font face="georgia, serif" style="font-size:12.800000190734863px">let says = NSLocalizedString("<div class="gmail_default" style="display:inline">blabla</div>\(count)<div class="gmail_default" style="display:inline">blabla</div>", comment: "<div class="gmail_default" style="display:inline">blabla</div>")</font></blockquote><div><br></div><div class="gmail_default" style="font-family:georgia,serif">to </div><div class="gmail_default" style="font-family:georgia,serif"><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font face="georgia, serif">let says = String.localizedStringWithFormat(NSLocalizedString("blabla%@blabla", comment: "blabla"), String(count)</font></blockquote><div><span style="font-family:georgia,serif"><br></span></div><div><span style="font-family:georgia,serif">When encounter `</span><span style="font-family:georgia,serif;font-size:12.800000190734863px">NSLocalizedString`, Swift looks into its key, if it<div class="gmail_default" style="font-family:georgia,serif;display:inline">s key</div> contains \(foo), just replace it as `</span><span style="font-family:georgia,serif">String.localizedStringWithFormat(NSLocalizedString("blabla%@blabla", comment: "blabla"), String(foo)</span><span style="font-family:georgia,serif">`. If not, keep it unchanged.</span></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">That is enough.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><font face="georgia, serif">In current situation, Swift still first calculates the value of string first, then `<span style="font-size:12.800000190734863px">NSLocalizedString` work. So it just needs to add a little work to check if there is any `\(foo)` in the string, instead of calculating the value of string.</span></font></div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 2, 2016 at 2:09 PM, Jens Alfke <span dir="ltr"><<a href="mailto:jens@mooseyard.com" target="_blank">jens@mooseyard.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Nov 1, 2016, at 10:56 PM, Zhao Xin <<a href="mailto:owenzx@gmail.com">owenzx@gmail.com</a>> wrote:<br>
><br>
> I am not talking to eliminate "%" style function. I am talking to add more compatibility to `NSLocalizedString` with `\(foo)` style.<br>
<br>
</span>I don’t think the ExpressibleByStringInterpolati<wbr>on protocol provides enough information to make this work. It hands the implementation a list of values to concatenate, some of which are strings, but as far as I can tell there’s no way to tell which of those strings are the pieces of the string literal and which of them are the results of expressions. So NSLocalizedString would not be able to reassemble the string template that you gave it, to look up in the localization table.<br>
<br>
If I’m wrong about this, show me a workable implementation of it. :)<br>
<br>
Also, ExpressibleByStringInterpolati<wbr>on is marked as being deprecated and will be “replaced or redesigned in Swift 4.0.” Maybe to solve this limitation?<br>
<span class="HOEnZb"><font color="#888888"><br>
—Jens</font></span></blockquote></div><br></div>