[swift-users] Localization in Swift.

Jens Alfke jens at mooseyard.com
Wed Nov 2 01:09:29 CDT 2016


> On Nov 1, 2016, at 10:56 PM, Zhao Xin <owenzx at gmail.com> wrote:
> 
> I am not talking to eliminate "%" style function. I am talking to add more compatibility to `NSLocalizedString` with `\(foo)` style.

I don’t think the ExpressibleByStringInterpolation 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.

If I’m wrong about this, show me a workable implementation of it. :)

Also, ExpressibleByStringInterpolation is marked as being deprecated and will be “replaced or redesigned in Swift 4.0.” Maybe to solve this limitation?

—Jens


More information about the swift-users mailing list