Django内部化不起作用,按照教程一步一步地进行

时间:2022-06-11 16:35:28

I am really getting annoyed by this. So I have the following structure:

我真的很生气。所以我有以下结构:

project/
   project/
   locale/
      fr/
        locale/
          LC_MESSAGES/
              django.po
              django.mo
   templates/

I have

我有

USE_I18N = True

USE_I18N = True

USE_L10N = True

USE_L10N = True

LANGUAGE_COOKIE_NAME = 'django_language'

LANGUAGE_COOKIE_NAME = ' django_language '

LOCALE_PATHS = '/Users/xxxx/Programming/Projects/xxxx/locale'

LOCALE_PATHS = ' /用户/ xxxx /编程/项目/ xxxx /地区”

LANGUAGES = ( ('en', gettext_noop('English')), ('fr', gettext_noop('French')), )

语言=((“en”,gettext_noop(英语)),(“fr”,gettext_noop(法国)),)

I mostly have my strings to translate in my templates which are in the templates directory.

在模板目录中的模板中,我主要有要转换的字符串。

Within my app, it seems like I am setting the language correctly, since I can see the django password forms are changing from French to English. It is just MY templates are not getting translated.

在我的应用程序中,我似乎正确地设置了语言,因为我可以看到django密码形式从法语变成了英语。只是我的模板没有被翻译。

Thanks!

谢谢!

1 个解决方案

#1


1  

LOCALE_PATHS is a tuple, as stated in https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths

LOCALE_PATHS是一个元组,如https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths所述

If you provide a string, Django considers it as a tuple (of characters) and probably loops through all the characters one by one, looking for templates in there.

如果您提供一个字符串,Django将它视为一个元组(字符),并可能逐个循环所有字符,在其中查找模板。

If you have a single directory remember to write it as a tuple, i.e. ('string', ) and not ('string'), if you have more then ('string1', 'string2') is fine.

如果您有一个目录,记得把它写成tuple,也就是('string',)而不是('string'),如果您有更多的话('string1', 'string2')很好。

#1


1  

LOCALE_PATHS is a tuple, as stated in https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths

LOCALE_PATHS是一个元组,如https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths所述

If you provide a string, Django considers it as a tuple (of characters) and probably loops through all the characters one by one, looking for templates in there.

如果您提供一个字符串,Django将它视为一个元组(字符),并可能逐个循环所有字符,在其中查找模板。

If you have a single directory remember to write it as a tuple, i.e. ('string', ) and not ('string'), if you have more then ('string1', 'string2') is fine.

如果您有一个目录,记得把它写成tuple,也就是('string',)而不是('string'),如果您有更多的话('string1', 'string2')很好。