我正在尝试使用 babel 来提取和更新构造的字符串,但我仍然没有找到一个好的方法(没有任何麻烦)
我目前构造字符串的方法:
def calculate_money(amount):
(usd, cent) = calculate(amount)
if not (usd or cent):
return ''
params = {}
result = 'Buying this will cost you '
if usd:
result += '%(usd) USD'
params['usd'] = usd
if cent:
if params:
result += ' and '
result += '%(cent) cent'
params['cent'] = cent
result += '.'
return gettext(result, **params)
我知道这pybabel
不会提取动态字符串,所以我把它放到en.po
,de.po
等zh.po
文件中
msgid "Buying this will cost you %(usd) USD."
msgstr ""
msgid "Buying this will cost you %(cent) cent."
msgstr ""
msgid "Buying this will cost you %(usd) USD and %(cent) cent."
msgstr ""
但是当我跑步时
pybabel update -i messages.pot -d translations --previous
它把我珍贵的msgid
部分放入评论中#~
!
你能帮我找到一种更好的方法来处理这个特定的用例吗?非常感谢和提前拥抱!