[Python-ideas] Combine f-strings with i18n

Chris Angelico rosuav at gmail.com
Mon Sep 17 04:59:54 EDT 2018


On Mon, Sep 17, 2018 at 5:53 PM, Niki Spahiev <niki.spahiev at gmail.com> wrote:
> On 14.09.2018 12:33, Chris Angelico wrote:
>>
>> On Fri, Sep 14, 2018 at 7:02 PM, Hans Polak <hpolak at polak.es> wrote:
>>>
>>> I have recently updated my code to use the more pythonic f-string instead
>>> of
>>> '{}'.format()
>>
>>
>> Well there's your problem right there. Don't change your string
>> formatting choice on that basis. F-strings aren't "more Pythonic" than
>> either .format() or percent-formatting; all three of them are
>> supported for good reasons.
>>
>> For i18n, I think .format() is probably your best bet. Trying to mess
>> with f-strings to give them methods is a path of great hairiness, as
>> they are not actually objects (they're expressions).
>
>
> Is it possible to use f-strings when making multilingual software?
> When i write non-hobby software translation is hard requirement.

I won't say it's *impossible*, but it's certainly not what I would
recommend. Use one of the other formatting methods (percent formatting
or the .format() method), since they start with a single string object
rather than an expression.

Don't assume that f-strings should be used for everything just because
they're newer. They have their place, and that place is NOT
translation.

ChrisA


More information about the Python-ideas mailing list