[swift-users] Localization in Swift.

Zhao Xin owenzx at gmail.com
Tue Nov 1 03:53:19 CDT 2016

I encountered a localization problem today. At first I translated a string
like this.

let count = 10
> let says = NSLocalizedString("It runs \(count) times", comment: "run
> times")

I couldn't get the translation taking effect.

So I open the setting "Localization Debugging" in scheme and get this error:

[strings] ERROR, It runs 10 times not found in table Localizable of bundle
> CFBundle 0x100c01c40 ... (executable, loaded)

I began to realize that` \(count)` was not dealed well in localization. The
compiler calculated the full string then looking for the translation,
instead of looking for the translation first.

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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161101/93877182/attachment.html>

More information about the swift-users mailing list