[swift-users] Localization in Swift.
Dave Abrahams
dabrahams at apple.com
Wed Nov 2 14:50:37 CDT 2016
on Tue Nov 01 2016, Jens Alfke <swift-users-AT-swift.org> wrote:
>> On Nov 1, 2016, at 10:40 PM, Zhao Xin <owenzx at gmail.com> wrote:
>>
>> For example, if I want show the user that I have to ask him to give me permission of a folder, the
> `url.path` has no need to translate.
>
> We’re getting off-topic, but paths do need to be translated, at least
> on Mac systems. The names of many standard folders like “Applications”
> and “Documents” are hardwired to English in the filesystem but are
> localized in the UI. Some application names get localized too (there’s
> a table in the app’s Info.plist that can substitute localized names.)
>
> Anyway, string interpolation is convenient, but I wouldn’t say it
> should be the only way to format strings in Swift; it’s a lot less
> flexible than the C-style “%” substitutions. For comparison, even
> though C++’s iostreams use “<<“ to format strings by concatenation, I
> still end up using “%” based formatting a lot, depending on the use
> case.
I'm actually working on design in this area right now.
%-style formatting has the following drawbacks
- for anyone who doesn't use them regularly they are cryptic and
complex, as the printf (3) man page attests.
- the spelling of these placeholders must match up to the types of the
arguments, in the right order, or the behavior is undefined. Some
limited support for compile-time checking of this correspondence could
be implemented, but only for the cases where the format string is a
literal.
- there's no reasonable way to extend the formatting vocabulary to cover
the needs of new types: you are stuck with what's in the box.
In my opinion, we can and must do much better for Swift. If there's
something about “%” formatting that you particularly value, I'd like to
know about it, so I can make sure it's accomodated.
Thanks,
--
-Dave
More information about the swift-users
mailing list