2016-11-22 65 views
0

我是韓國人,在我的Django項目中使用django-all-authDjango-all-auth:語言翻譯不起作用

我檢查了django-all-auth中有韓文.po文件。

但所有的表達式都是英文,而不是韓文。

我只是遵循doc中的安裝部分和配置部分。

這裏是我的settings.py

LANGUAGE_CODE = 'ko-kr' 

TIME_ZONE = 'Asia/Seoul' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 

我錯過了什麼?

+0

你檢查你的URL模式是118N ? url(r'^ accounts /',include('allauth.urls'))在哪裏? –

+0

@ShashishekharHasabnis感謝您的建議。我推薦您的建議並編輯這樣的網址代碼:https://gist.github.com/rightx2/7a15208cb24e4c88b6c23a67b4543964。當我訪問singup頁面時,網址顯示如下:http:// localhost:8000/ko-kr/accounts/login /,但語言仍然是英文。 (其他網頁也是英文的) – user3595632

回答

-1

由於現在您的頁面已配置爲路由到所需的國際化,您現在需要自行提供本地化。他們不會自動翻譯。你需要自己處理它。 要做到這一點,你必須標記需要通過使用

from django.utils.translation import ugettext as _ 

現在標記,你需要通過下列方式使用ugettext as _翻譯的文本翻譯的元素: -

class PollPluginPublisher(CMSPluginBase): 
    model = PollPluginModel # model where plugin data are saved 
    module = _("Polls") 
    name = _("Poll Plugin") # name of the plugin in the interface 

現在元素被標記爲在我們的案例中被翻譯(「民意調查」)和(「民意調查插件」)。 處理此之後,你可以在你的根目錄下運行以下命令: -

django-admin makemessages -l de 

替換最後一個「德」與您的語言環境的名字。這個命令的作用是創建一個只存儲需要翻譯的元素的po文件。確保您的LOCALE_PATH設置正確。

在此之後做,你可以使用下面的Django的包翻譯: -

1) django-rosetta :- https://django-rosetta.readthedocs.io/en/latest/ 

2) django-modeltranslation:- http://django-modeltranslation.readthedocs.io/en/latest/ 

本地化的進一步參考,您可以查看: -

https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#localization-how-to-create-language-files