[swift-users] Localization in Swift.

Brent Royal-Gordon brent at architechies.com
Tue Nov 1 05:40:25 CDT 2016


> I managed to replace my code with 
> 
> let newSays = String.localizedStringWithFormat(NSLocalizedString("It runs %d times", comment: "new run times"), count)
> 
> However, I still thing it would be better if we could use \(foo) directly, as it is more Swift style. Any idea why this can't happen?

I have some code that does that (Swift 2 version: <https://gist.github.com/brentdax/79fa038c0af0cafb52dd>), but it relies on the ExpressibleByStringInterpolation protocol, which is currently deprecated because it's due for a redesign.

Ultimately, localization is a Foundation-level concern. I'd love to see a future Foundation do something clever with NSLocalizedString, but it seems like their hands have been full with higher-priority stuff like the value-type equivalents.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-users mailing list