[swift-users] Localization in Swift.

Zhao Xin owenzx at gmail.com
Thu Nov 3 08:09:44 CDT 2016


I just uploaded this as a Xcode extension. You can download it here
<https://github.com/owenzhao/Localization-Helper>.
As long as Swift is not supporting this, you can use my Xcode extension.

Zhaoxin

On Thu, Nov 3, 2016 at 10:36 AM, Zhao Xin <owenzx at gmail.com> wrote:

> Hello everyone. Thanks to you all for replies in this thread.
>
> I am currently working on a Xcode Extension for this purpose. I would like
> to bring it to github in this week. This will be my first Xcode extension,
> also my first github open sourced project.
>
>
> Zhaoxin
>
> On Thu, Nov 3, 2016 at 6:14 AM, Dave Abrahams via swift-users <
> swift-users at swift.org> wrote:
>
>>
>> on Wed Nov 02 2016, Jens Alfke <jens-AT-mooseyard.com> wrote:
>>
>> >> On Nov 2, 2016, at 12:50 PM, Dave Abrahams via swift-users <
>> swift-users at swift.org> wrote:
>> >>
>> >> 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.
>> >
>> > It offers more control over formatting, like min/max widths, number
>> > base, decimal places, etc. Yes, you can do this in the code inside the
>> > interpolated string, but IMHO it’s awkward because it requires knowing
>> > a bunch of extra methods for string conversion, truncation, etc. It’s
>> > a lot easier for me to remember and type “%x” than it is to remember
>> > and type the method that converts an int to a hex string.
>>
>> In my view this should look like
>>
>>   "... \(x.format(radix: 16, width: 12))... "
>>
>> Where the possible arguments to format() are statically known to the
>> compiler (and code completion!) based on the type of x.
>>
>> >
>> > Also (and more importantly for localization) the formatting details
>> > are part of the localizable format string, not hardwired. One example
>> > of this is formatting currency, where a US localization would use
>> > “$%.2f” but other currencies might call for more or fewer decimal
>> > places.
>>
>> Yep, I'm paying attention to that, thanks.
>>
>> > There are other examples where one might swap format strings for other
>> > purposes like different-width layouts for monospaced/terminal output.
>>
>> I think we can leverage the same mechanisms used for localization to
>> handle those.
>>
>> > There’s also a nonstandard extension used by Cocoa/CF’s formatters,
>> > that allows the parameters to be reordered. (I haven’t used it so I
>> > don’t know the syntax offhand.) This is of course important for
>> > localization, to follow a language’s grammar.
>>
>> Right, that's crucial.
>>
>> > I think these features could be added to interpolation. Just as a
>> > quick idea, maybe a syntax that allows formatting metacharacters to be
>> > added at the start of the interpolation, like “Please pay $\((.2)
>> > total)” where the “(.2) specifies two decimal places, or “The address
>> > is \((x) addr)”.
>>
>> I think the “.format(...)” approach is better, but it's equally
>> important that there are sufficient outside-the-Swift-source knobs for
>> localizers to add language-specific formatting parameters.
>>
>> --
>> -Dave
>> _______________________________________________
>> swift-users mailing list
>> swift-users at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161103/02f69bef/attachment.html>


More information about the swift-users mailing list