2011-12-30 2 views
3

내 제안 사이트에서 사용자가 일부 요구 사항 (모델에 지정된 필터)을 충족하는 경우 이메일 알림을 설정할 수 있습니다.django가 UserProfile.language() 필드 데이터에 따라 현지화 된 이메일을 전송합니다.

그래서 사용자 "A"가 쿠폰을 추가하면 post_save 신호가 셀러리에 전송되고 사용자 경고 필터가 적용되는지 확인하고 이메일이 전송되는지 확인합니다.

문제는 전송 된 각 이메일에 대해 안전하게 콘텐츠를 설정하는 방법을 모르는 것입니다. 서비스는 더 많은 언어로 제공됩니다. 사용자 (사용자 <를 통해 - Userprofile.language()) 자신의 프로필에서 언어를 변경할 수 있도록 각 이메일은 언어 UserProfile.language로 설정해야 필드() 값을 ...

가 translation.activate와 시도 (userinstance.UserProfile합니다. 언어)하지만 예상대로 작동하지 않습니다. translate.activate()는 전체 스레드에 대한 변환 활성화를 수행합니까?

PS : 이메일 콘텐츠가 템플릿에서 렌더링됩니다. 나를 위해

답변

9

translation.activate 작품 :

$ ./manage.py shell 
Python 2.7.2 (default, Jan 20 2012, 15:23:49) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
(InteractiveConsole) 
>>> from django.utils import translation 
>>> translation.get_language() 
'en-us' 
>>> translation.ugettext('E-mail address') 
u'E-mail address' 
>>> translation.activate('fr') 
>>> translation.ugettext('E-mail address') 
u'Adresse électronique' 

템플릿도 작동 : 그것은 당신을 위해 작동하지 않는 이유

>>> from django.template import Context, Template 
>>> Template('{% load i18n %}{% trans "E-mail address" %}').render(Context()) 
u'Adresse électronique' 

모르겠어요. UserProfile.language() 함수는 어떤 종류의 값을 반환합니까?

+0

내 UserProfile 모델에서 "선택 사항"필드에 settings.LANGUAGES를 사용합니다. 나는 내 서비스에서 번역을 재 작성하려하고 있지만 귀하의 게시물은 내가 올바르게하고 있음을 확인합니다. 감사 – Robert

관련 문제