如何在python> 3.6 f字符串中使用gettext [英] How to use gettext with python >3.6 f-strings

查看:60
本文介绍了如何在python> 3.6 f字符串中使用gettext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,您将按以下方式使用gettext:

Previously you would use gettext as following:

_('Hey {},').format(username)

但是新Python的f字符串呢?

but what about new Python's f-string?

f'Hey {username}'

推荐答案

'Hey {},'按原样包含在翻译词典中.

'Hey {},' is contained in your translation dictionary as is.

如果使用f'Hey {username},',则会创建另一个字符串,该字符串将不会被翻译.

If you use f'Hey {username},', that creates another string, which won't be translated.

在这种情况下,format方法仍然是唯一可用的方法.

In that case, the format method remains the only one useable.

这篇关于如何在python> 3.6 f字符串中使用gettext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆