2009-08-31 44 views
2

我回顧文檔,但我迷路了......有些問題是:如何創建翻譯到「timesince」值? (模板標籤)

{% load i18n %} 
{% blocktrans %} 
{{ wpis.entry.lastChangeDate|timesince }} 
{% endblocktrans %} 

升起:

`KeyError: u'wpis.entry.lastChangeDate | timesince'` 

當然,沒有blocktrans一切工作正常。

那麼,翻譯幾句話的簡單方法是什麼? (我很有趣波蘭郎,分鐘 - > minut,小時 - > godzin等) 我會感謝你的明確例子。

編輯: 在我的.po文件我現在有:

#: templates/part.html:37 
#, python-format 
msgid "" 
"\n" 
"%(lastChangeDate)s\n" 
msgstr "" 

,我沒有看到有關文檔VAR什麼...現在我會做:

msgid "hours" 
msgstr "godzin" 

等並將其綁定到我的VAR(上面的例子不工作...)

回答

2
{% load i18n %} 
{% blocktrans with wpis.entry.lastChangeDate|timesince as lastChangeDate %} 
{{ lastChangeDate }} 
{% endblocktrans %} 

更多INF見http://docs.djangoproject.com/en/dev/topics/i18n/#in-template-code O操作。

+0

Thx的答案,但在那種情況下,我應該把波蘭話? – IProblemFactory 2009-09-01 08:54:44

+0

對不起,我更新了一個更好的方法來執行此操作。 – David 2009-09-01 09:46:11

+0

但我仍然只有英文單詞,在setting.py lang是「pl」 – IProblemFactory 2009-09-01 10:11:14

1

只需使用{{ var|timesince }}並確保在settings.py中,LANGUAGE_CODE設置爲您的語言環境,而USE_I18NTrue

您不需要在.po文件中使用blocktrans或自定義翻譯,因爲它已包含在內。