教程:
https://docs.djangoproject.com/zh-hans/4.0/topics/i18n/translation/参考项目:
https://github.com/saleor/saleor简单说就是 3 步(必须保证配置文件 USE_I18N = False ):
1 ,在用的地方:
from django.http import HttpResponse
from django.utils.translation import gettext as _
def my_view(request):
output = _("Welcome to my site.")
return HttpResponse(output)
2, 创建翻译文件(生成.po )
django-admin makemessages
msgid "Welcome to my site."
msgstr ""
3 ,编译翻译文件(生成 mo 文件)
django-admin compilemessages