我已经在马达加斯加语(mg_Mg)中翻译了我的项目,但是在安装django-allauth和替代模板时,将不应用翻译。
在python manage.py makemessages
之后,python manage.py compilemessages
并测试了一些翻译,例如:sign up -> Hisoratra anarana
在渲染中显示sign up
。
但是在我的本地应用程序中,所有模板均已正确翻译。
在config / setting.py
import environ
BASE_DIR = environ.Path(__file__) - 2
...
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
LANGUAGES = [
('en-us', 'English'),
('fr-fr', 'French'),
('mg-mg', 'Malagasy'),
]
LOCALE_PATHS = [BASE_DIR('locale')]
在fandaharana / views.py
def month(request, month_num, year_num):
translation.activate('mg-mg')
...
return render(request, 'month.html', data)