我需要使用惰性翻译,但也需要进行翻译-如何处理?
这段代码正在做我需要的:
print ugettext_lazy('Hello world!')
现在,我想将两个惰性翻译合并在一起并分别翻译(我现在不起作用,为什么但要有两个翻译字符串)。
print ugettext_lazy('Hello world!') + ' ' + ugettext_lazy('Have a fun!')
我可以做这样的代码,但是它会产生比需要更多的翻译。
print ugettext_lazy('Hello world! Have a fun!')
是否可以同时使用两个翻译字符串和惰性翻译?
由于django 1.11string-concat
已被弃用,format_lazy
应改为使用
from django.utils.text import format_lazy
from django.utils.translation import ugettext_lazy
name = ugettext_lazy('John Lennon')
instrument = ugettext_lazy('guitar')
result = format_lazy('{} : {}', name, instrument)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句