Django: default language i18n

后端 未结 3 1488
耶瑟儿~
耶瑟儿~ 2021-02-07 05:45

I have a website that is written in dutch. Now I have to provide a second language for that website which is french.

So I surrounded all text that needs to be translate

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-07 06:37

    Default language strings are not stored in po/mo files, they go directly in code and templates - seems that you have this right.

    You can switch back to it, by setting the session variable django_language back to dutch.

    Ensure, that you have your settings set the right way:

    LANGUAGE_CODE = 'nl' #default language
    
    LANGUAGES = (
      ('nl', _('Dutch')),
      ('fr', _('French')),
    )
    

    Don't forget, that you don't have to write code to switch between languages by your self. Better to use special django view (quote from django book):

    As a convenience, Django comes with a view, django.views.i18n.set_language, that sets a user’s language preference and redirects back to the previous page.

    Activate this view by adding the following line to your URLconf:

    (r'^i18n/', include('django.conf.urls.i18n')),
    

提交回复
热议问题